Use SimpMessagingTemplate without creating a web socket message broker Spring 4 - spring

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.

Related

PCF app connecting to Spring AMQP - different messaging service after binding app to RabbitMQ service

I am new to PCF and need some help understanding the root cause of an issue I am facing.
We have one PCF application that is connecting to Rabbit MQ (no binding done on the Rabbit MQ service yet). the messages get passed through the application to queues created on this Rabbit MQ instance. so far so good.
But when we bind again the application to the same Rabbit MQ instance and restage the application, it starts getting connected to a different messaging instance and the message is being relayed to that messaging service and no message transfer happened on expected Rabbit MQ instance although I can't see the actual movement of messages because I might not be having access to the mystery messaging service (I say that because two spring boot services are communicating as expected and the process gets completed).
I am clueless as to what is changing in the application by binding it to Rabbit MQ. is it a default spring implementation of spring AMQP which is interfering here? what can I do to stop this behavior? I haven't provided any parameters while binding the app to Rabbit MQ.
I tried to put the loggers to find out the name of the exchange it's getting connected to but it's still the same exchange, but I can't see the messages flowing and can't explain the phenomenon to the client.
Try to look at the service key of the your rabbit instance and that will give you hostname etc. i.e. rabbitmq details where you are connecting to after binding.
cf service-key SERVICE_INSTANCE SERVICE_KEY
Not sure if there is any default setting in the app that's being used for setting up the connection to a different rabbit instance in absence of binding.

Difference between SockJS and ActiveMQ/RabbitMQ

I have recently developed a simple messaging application with Spring Boot and Spring Security. The application takes in 2 users - user A and user B. Once, user A performs a specific task a notification is sent to user B. Currently I am doing this by adding a Spring Messaging dependency and SockJS and it works great.
Here is where I am confused and hoping to receive some guidance. I realize there are many tutorials that speak about RabbitMQ and ActiveMQ. From what I understand, they are message brokers. May I ask what is the difference between SockJS and RabbitMQ/ActiveMQ? And do I need RabbitMQ/ActiveMQ in my current application together with SockJS?
SockJS is JavaScript based WebSocket client library that runs in a browser. It can be used to send messages to or receive messages from a broker.
Both RabbitMQ and ActiveMQ are message brokers, examples of message-oriented middleware. They both support WebSocket clients which use a messaging protocol (e.g. STOMP or AMQP). Brokers receive messages from and dispatch messages to clients.
You haven't really provided enough information to determine whether or not you actually need to use either RabbitMQ or ActiveMQ in your current application given that it's already working as it is.

Spring Integration Kafka : Inbound channel adapter vs message driven adapter

I am new to using spring integration kafka. I was reading the docs, and got confused between Inbound channel adapter and message driven channel adapters. Can some one explain the difference between them . Also does spring integration for kafka has some error handling mechanism like the one present in spring integration for amqp/rmq( using dlq).
PS : We are trying to move away from rabbit mq to kafka as source of messages in ithe spring integration framework
thanks,
The message-driven adapter is similar to the rabbitmq inbound adapter in that messages are "pushed" into your integration flow whenever records are available in the topic.
The inbound channel adapter uses the "pull" model, where you poll for messages on a schedule. There is an equivalent for RabbitMQ (since 5.0.1) but it's not currently configurable with XML.
some error handling mechanism
The SIK components are subclasses of the same classes as all other SI components, so the same facilities are generally available, yes.

spring-boot-starter-amqp will works between micro services?

I am new to Spring amqp.
I have tried to send the messages by following: https://spring.io/guides/gs/messaging-rabbitmq/
I am able to send the messages within the micro services.
But unable to send the messages to another micro services ? Is it expected ?
If I want to send the messages between the micro services which dependency I should follow ?
Please help me here.
What you want is something like this (figure taken from a recent blog post of mine, which also shows more detailed code examples):
Here, as an example, CRUD-Events like "customer.created" or "order.deleted" are considered
Any microservice can act as an Event Producer and send events to an event exchange via RabbitTemplate, which is provided by Spring AMQP and can just be injected into any Spring Bean.
A cluster of instances of the same microservice share a queue.
The consuming microservices declare their queue and the binding between queue and event exchange by declaring #Beans of type Queue and Binding with the same attributes.
The binding defines which events will be received by each microservice cluster
All microservices must share the same event exchange by declaring a #Bean of type Exchange with the same exchange name.
In one service you would send the message and in an other receive it. In the example you now have both in 1 project. In the sending service you have the RabbitTemplate and in the other service the Receiver with the SimpleMessageListenerContainer and MessageListenerAdapter beans. Make sure that the binding, queue and exchange configuration are the same and the services are both connected to the same RabbitMQ server.

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