Chris
Chris

Reputation: 3657

RabbitMQ subscription endpoint with STOMP, unsure what it should be

I'm using spring-boot-starter-amqp to push messages into RabbitMQ. I have set the exchange as spring-boot-exchange and the routing key as group.n (n being dynamic)

Attempting to read messages sent into this channel with Angular using ng2-stompjs. I can open a connection to RabbitMQ but I never get any messages.

Very default settings for RxStompConfig

export const myRxStompConfig: InjectableRxStompConfig = {
  brokerURL: 'ws://127.0.0.1:61613/ws',
  connectHeaders: {
    login: 'guest',
    passcode: 'guest'
  },
  heartbeatIncoming: 0,
  heartbeatOutgoing: 20000,
  reconnectDelay: 200,

  debug: (msg: string): void => {
    console.log(new Date(), msg);
  }
};

Based on my exchange and routing key I would have expected the following to consume a message when one is posted by the Spring server.

this.rxStompService.watch(`spring-boot-exchange/group.${this.group.id}`).subscribe((message: Message) => {
  console.log("new message!");
});

(Where the this.group.id matches that set in the Spring service)

Edit:

Configuration on the Spring side

@Configuration
public class RabbitConfig {

    private static final String topicExchangeName = "spring-boot-exchange";

    private static final String queueName = "spring-boot";

    @Bean
    public Queue queue() {
        return new Queue(queueName, false);
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(topicExchangeName);
    }

    @Bean
    public Binding binding(final Queue queue, final TopicExchange exchange) {
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with("group.#");
    }
}

What have I misunderstood here?

Upvotes: 0

Views: 1994

Answers (1)

Chris
Chris

Reputation: 3657

Got it working after I found the section "AMQP 0-9-1 Semantics" in the documentation here:

The destination header on a MESSAGE frame is set as though the message originated from a SEND frame:

messages published to the default exchange are given the destination /queue/queuename; messages published to amq.topic are given the destination /topic/routing_key; all other messages are given the destination /exchange/exchange_name[/routing_key].

source: https://www.rabbitmq.com/stomp.html#

So the correct endpoint for my use case is:

/exchange/spring-boot-exchange/group.5d550aaa8cadeaa03dc3adc1

The key here being the exchange keyword. Then I can simply use my custom exchange name, along with whatever routing key I decide.

Upvotes: 0

Related Questions