0

I have a rabbitMQ container running from docker compose:

services:
  rabbitmq-demo:
    image: rabbitmq:3.13-management # Using management tag for easier monitoring
    hostname: rabbitmq
    ports:
      - "5672:5672" # AMQP port
      - "15672:15672" # Management UI
      - "61613:61613" # STOMP port
      - "15674:15674" # Web STOMP port (for browser-based clients if needed)
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest
    volumes:
      - ./rabbitmq-enabled-plugins:/etc/rabbitmq/enabled_plugins:ro # i.e. rabbitmq_stomp

I have a producer spring boot simple microservice which produces STOMP messages

@Service
@EnableScheduling
public class MessageSender implements ApplicationListener<BrokerAvailabilityEvent> { // Implement ApplicationListener

    private final SimpMessagingTemplate messagingTemplate;

...

    @Scheduled(fixedRate = 5000)
    public void sendMessage() {
        if (brokerAvailable) { // Only send if the broker is confirmed active
            String message = "Hello from Producer Service! Message #" + messageCount++;
            System.out.println("Sending message: " + message);
            messagingTemplate.convertAndSend("/topic/public.messages", message);
        } else {
            System.out.println("Broker not active. Skipping message sending.");
        }
    }

That works fine and I see message rate in (0.20/s) in the rabbitMQ ui for amq.topic exchange. I see also messages creation log lines in the app console.

Next I have a consumer spring boot microservice with controller:

@RestController
public class MessageController {

    @MessageMapping("/topic/public.messages") // This maps to the topic Service A is sending to
    public void receiveMessage(@Payload String message) {
        System.out.println("Received message from Producer Service: " + message);
        // You can add logic here to process the received message
    }

    @PostConstruct
    public void init() {
        System.out.println("MessageController @PostConstruct called!");
    }
}

But this is not reading the messages. In the rabbitMQ web ui I see 4 connections (2 stomp, 2 amqp), 4 channels (1 is running with message rate in non-zero). I see the rate on amq.topic exchange, but this topis is not bound to any queue and no queue is created.

Both microservices have common configuration:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(@NonNull MessageBrokerRegistry registry) {
        registry.enableStompBrokerRelay("/topic", "/queue")
                .setRelayHost("localhost")
                .setRelayPort(61613)
                .setClientLogin("guest")
                .setClientPasscode("guest")
                .setSystemLogin("guest")
                .setSystemPasscode("guest");
        registry.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(@NonNull StompEndpointRegistry registry) {
        registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
    }

}

How to fix the consumer to read the messages?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.