question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring cloud stream RabbitMQ routing messages dynamically

See original GitHub issue

I have implemented the example as shown here Dynamic Destinations Spring Dynamic Destination

In the rabbitmq, it is creating an exchange dynamically, but there is no option to provide binding or routing key. My requirement is to send a message to this dynamically created exchange with a routing key. How would i need to implement this to setup the routing key?

@Component public class DDProducerBean {

@Autowired
private BinderAwareChannelResolver poChannelResolver = null;

public void publish(DDSocketVO ddSocketVO) throws Exception {
    this.poChannelResolver.resolveDestination(ddSocketVO.getDestination()).send(MessageBuilder.withPayload(new ObjectMapper().
            setVisibility(PropertyAccessor.FIELD, Visibility.ANY).
            writeValueAsString(ddSocketVO)).build());
}

My requirement is to route messages dynamically at runtime based on the payload. So i need a way to set the routing key at run time. As a result i can’t use producer.routingKeyExpression, which is done in config or properties or yml, and not dynamically at run time, so that won’t serve the purpose.

This implementation is specific for spring.cloud.stream.dynamicDestinations where the BinderAwareChannelResolver takes care of dynamically creating/binding the outbound channel for these dynamic destinations. But it doesn’t talk about how to bind the outbound channel to a queue and how to specify a routing key expression. As these are dynamic channels/ producers, we can’t use producer.routingKeyExpression as the producer is created dynamically.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
abhdebcommented, Jul 5, 2017

Based on your suggestion we have now created the binding using AmqpAdmin and a routing key and it is working as expected, thank you.

Just curious as why routing key api is not available in dynamic destinations? In this scenario every time a new exchange is created and then using AmqpAdmin bind it to the defualt exchange with the routing key, which seems like a workaround. Ideally when we send a message, if we can send the routing key, then exchange can route it according without having to create new exchange for each request and then bind them using AmqpAdmin.

1reaction
garyrussellcommented, Jul 5, 2017

Producers are not responsible for binding queues; consumers are.

There is some support for a producer binding queues using the requiredGroups property, but that is for fixed destinations; there is no such support for dynamic destinations.

You can programmatically declare queues and bindings using the AmqpAdmin bean after you have resolved the destination and before sending messages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring cloud stream RabbitMQ routing messages dynamically
Here is the workaround as suggested Here. Basically create a MessageChannel with the dynamic destination using BinderAwareChannelResolver, ...
Read more >
Spring Cloud Stream RabbitMQ Binder Reference Guide
This guide describes the RabbitMQ implementation of the Spring Cloud Stream Binder. It contains information about its design, usage and configuration ...
Read more >
Spring cloud stream RabbitMQ routing messages dynamically
In the rabbitmq, it is creating an exchange dynamically, but there is no option to provide binding or routing key. My requirement is...
Read more >
Spring cloud stream RabbitMQ routing messages dynamically ...
[Solved]-Spring cloud stream RabbitMQ routing messages dynamically-Java ... Basically create a MessageChannel with the dynamic destination using ...
Read more >
spring-cloud/spring-cloud-stream - Gitter
. . .Spring Cloud Stream lets applications send messages to dynamically bound destinations. This is useful, for example, when the target destination needs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found