1

I have a question regarding spring-messaging (spring integration + amqp) with RabbitMQ. I have an application which based on microservices architecture. One service publish message in following way:

@EventListener(AfterCreationEvent.class)
@Publisher(channel = "messages")
public Message<Message> onCreateEntity(AfterCreationEvent<Message> event) {
    if (isDisabled()) return null;
    String id = event.getSource().getId();
    return MessageBuilder.withPayload(event.getSource())
            .build();
}

and other messages are listening, for instance

@StreamListener("messages")
public void onMessageReceived(@Payload Message input) {
    messageService.save(input)
}

Microservices have following base configuration:

spring:
  rabbitmq:
    host: rabbit
    port: 5672
  cloud:
    stream:
      bindings:
        messages:
          producer:
            required-groups: terminal,chat,security
          destination: message.share
          binder: rabbit
      binders:
        rabbit:
          type: rabbit

and each service has its own configuration for instance:

spring:
  application.name: message
  cloud:
    stream:
      bindings:
        messages:
          content-type: application/json

and

spring:
  application.name: terminal
  cloud:
    stream:
      bindings:
        messages:
          group: terminal

and it works fine. but it works in asynchronous way but I want to receive reply from each required group that message was delivered. Is it possible?

Right now I'm working with spring-integration-amqp:4.3.1.RELEASE

b3lowster
  • 415
  • 1
  • 6
  • 18

1 Answers1

1

messaging amqp is by it's nature asynchronous so by default you can't wait for replies. You need to implement the waiting mechanism by yourself. One way is to make use of the correlation IDs of a message.

Paul Vlasin
  • 304
  • 1
  • 9
  • The thing is that org.springframework.messaging.core.GenericMessagingTemplate has method doSendAndReceive but I cannot figure out how to configure message for publisher and using doSendAndReceive method – b3lowster Apr 09 '17 at 09:45