Collect Broadcast Responses

Dubbo broadcast2 broadcast mode collects port responses from all providers

Applicable scenario: for any Dubbo consumer, broadcast calls multiple service providers. The consumer is able to collect responses from all of the providers.


  • consumer demo

@Reference imports providers. Within the brackets, letting cluster = “broadcast2” represents doing one broadcast call that collects providers’ responses.

Broadcast calls all service providers one by one. Is able to return all service providers’ execution outcomes (success or exceptions) completely and stores providers’ responses in RpcContext.

public class TestServiceConsumer {
    @Reference(interfaceClass = DubboHealthService.class,cluster = "broadcast2")
    private DubboHealthService dubboHealthService;
         public String broadCast(){
             }catch (Exception e){
                 Map<String, String> m = RpcContext.getServerContext().getAttachments();
                 return m.toString()+"|"+"fail";
             Map<String, String> m = RpcContext.getServerContext().getAttachments();
             return m.toString()+"|"+"success";
  • provider demo
public class DubboHealthServiceImpl implements DubboHealthService {
    public String health() {
//        int i = 1/0;
        return "i am provider2";
  • execution outcome

All providers succeed:

>curl http://localhost:8081/health
>{broadcast.results=[{"ip":"","port":20880,"data":"i am provider1"},{"ip":"","port":20881,"data":"i am provider2"}]}|success%  

Let one of the providers divide by zero:

>curl http://localhost:8081/health
>{broadcast.results=[{"ip":"","port":20880,"data":"i am provider1"},{"ip":"","port":20881,"exceptionMsg":"/ by zero"}]}|success%