How to create temp queue in Spring Websocket - spring

While using Spring full-featured message broker using STOMP, it creates a queue for each new session, and by default the queue is durable. Is there a way to make queues per session non-durable(auto-delete).
I have tried adding headers like {'durable': false,'auto-delete': true} in SUBSCRIBE frame and, spring gives an error of MessageBroker not Active.

Related

What is the ideal way to store the consumer offset using spring boot kafka consumer client?

I have spring kafka consumer application. The application acts as pass through which polls the messages from kafka broker and send to IBM MQ. What would be a best/simplistic approach to store the offset in case of failure?
The simplest approach is to use the default mechanism of storing the offsets in kafka itself.
If you add a SeekToCurrentErrorHandler, the container will keep redelivering records that are failed in the listener, up to 10 times by default but it can be configured for infinite retries.
If you add stateful retry, the listener adapter can add a delay between each delivery attempt.
See Stateful Retry.
ackOnError should be set to false.

Apache Camel JMS/AMQP component create destination queue only if required

I am currently working on an Integration application that uses Camel with Spring Boot. There is a camel route in integration application that receive messages from source Artemis broker that is transformed and sent to another Artemis broker.
The camel route looks like this:
from(sourceQueue).process(transformProcessor).to(destinationQueue)
When the camel route starts, it recreates the queue names mentioned in the from and to and the previous messages are lost. We do not expect this to happen.
One way I found to do this is in the Artemis ActiveMQ broker.xml, disable the queue and topic auto creation and create the queue(s) using Artemis API.
My question is, can we configure camel JMS / AMQP component to create the queue only if it is not present and if present use the existing ones?
By default Camel will use DynamicDestinationResolver. You can create your own custom DestinationResolver and plug it in your endpoint (or into your component)
.to("jms:queue:myQueue?destinationResolver=MyCustomDestinationResolver");
You can also use JndiDestinationResolver, which by default does not fallback into creating a dynamic destination.
I don't know Artemis but it sounds weird for a broker to delete a queue with its messages. At least its "brother" ActiveMQ has by default the behavior you expect: queues are automatically created if they do not exist, but they just stay if they already exist.
Are you sure the queues are recreated on route start? Are these queues persistent? Could it be that a consumer just drains the queue? I also found a queue attribute of Artemis named auto-delete-queues that would delete the queue if it was drained by a consumer.
auto-delete-queues Whether or not to the broker should automatically delete auto-created JMS queues when they have both 0 consumers and 0 messages.

RabbitMQ Channel reuse (SimpleMessageContainer)

My spring boot application's is functionality it to listen to the messages on rabbitmq queue, do some processing in onMessage, and then publish the message on another rabbitmq queue. We are using spring-rabbit (1.7.2.RELEASE). We have configured listener using SimpleMessageListenerContainer.
My question is can i publish using he same channel on which I am reading he messages. Does spring-rabbit provides access to channel used by listener? so that same channel can be reused to publish?
Thanks,
Smita
If you use transactions (listener container), any operations performed by a transactional RabbitTemplate on the container thread will participate in the transaction and use the same channel.
If you are not using transactions, you can use a ChannelAwareMessageListener to access the channel the message was received on. See Message Listeners.
If you are using #RabbitListener you can add the Channel as a method parameter.
The current 1.7.x release is 1.7.9.

Use SimpMessagingTemplate without creating a web socket message broker Spring 4

Can I send a message to a message broker using SimpMessagingTemplate#convertAndSendToUser or SimpMessagingTemplate#convertAndSend methods without settings up a websocket message broker using #EnableWebSocketMessageBroker?
What I'm trying to do is utilise one websocket server to provide messaging for two application server instances(One spring 4 and one Spring 3). I created a one web server with Spring 4, Spring boot plus websocket message broker enabled.
Now I want two application servers to push messages to rabbitmq so it will broadcast them to clients subscribed to it.
First issue I faced is if there is no websockt message broker configuration available, SimpMessagingTemplate will not get autowired to application context. I couldn't get it injected without creating a websocket message board either.
Please help me to find out whether this is possible.
BTW I have a previous question unanswered related to this.
Well, After reading lots of documentation I found the answer myself. The key thing is this architecture is following.
In this architecture spring act as a gateway for communication between the message broker and client. Spring doesn't do anything(Other than when it necessary) but forward the request to the message broker(STOMP messages). The configuration kept on Spring defines couple of important things. One is the exchange and other were routing keys. Spring configuration gives us an abstract layer so we subscribe and push messages to message broker without a fuss.
SimpMessagingTemplate is the abstract layer which we use to communicate with message broker. Spring creates the bean using the given details. Well I couldn't create a instance of SimpMessagingTemplate manually. I have to update Spring 3 application to Spring 4 in order to use websockets.
Since Spring and message broker is decoupled, clustering the application instance doesn't make any effect on message broker. Spring will communicate to message broker only when it need to subscribe to a channel or when it need to publish a message to a channel. So if there is two instances subscribing to same channel it would be two queues binding the one exchange using same routing key. Messages published into a channel will be available to all subscribers(queues) because they all use same routing key. Refer to rabbitmq stop plugin documentation for more elaborative description.

How to get properly all queue messages from RabbitMQ in Spring?

I am using Spring, Spring-Websocket, STOMP for my application, and RabbitMQ as broker. I need to log all messages going through RabbitMQ to Postgresql tables.
I know that I can write #MessageMapping in Spring and log there, but my problem is that some clients talk to RabbitMQ directly through MQTT protocol, and Spring does not support it yet (https://jira.spring.io/browse/SPR-12581). Moreover browser clients talk through Spring to RabbitMQ using STOMP protocol.
RabbitMQ allows to track all messages using Firehose tracer. How to properly listen to amq.rabbitmq.trace topic from Spring? Or do I need to write separate Java app as consumer?
The Spring AMQP is for you!
You bind some custom queue to to that amq.rabbitmq.trace with appropriate pattern (e.g. publish.#) and configure SimpleMessageListenerContainer to receive messages from that queue.
It can be done even with pretty simple config: #EnableRabbit and #RabbitListener on some POJO method. Anyway the Binding #Bean must be there to attache your queue to that exchange.

Resources