Unable to send messages using AMQP with Spring boot JmsTemplate - spring-boot

I'm trying to send messages using the JmsTemplate of Spring boot.
I configure everything using the autoconfiguration through properties.
These are the properties I set :
spring.activemq.broker-url
spring.activemq.user
spring.activemq.password
I have been able to get this working as desired when I configure the broker-url to tcp://localhost:61616, but whenever I change it to amqp://localhost:5672, I get the error :
Failed to connect to [amqp://localhost:5672] after: 10 attempt(s) continuing to retry.
For a project I'm working on, I should be using AMQP.
Any ideas?
Thanks in advance!

Boot's support for activemq is JMS only.
Spring does not have support for AMQP 1.0 at all; only 0.9.1 with RabbitMQ.

Related

Spring Integration between two message brokers

I am new to Spring-Integration.
My use case is:
Listen to a RabbitMQ queue/topic, get the message, process it, send it to other message broker (mostly it will be another RabbitMQ instance).
Expected load: 5000 messages/sec
In application.properties we can set configurations for one host.
How to use Spring Integration between two message brokers?
All the examples that i see are for one message broker. Any pointers to get started with two message brokers and Spring Integration.
Regards,
Mahesh
Since you mention an application.properties it sounds like you use Spring Boot with its auto-configuration feature. It is very important detail in your question because Spring Boot has opinion about auto-configuration and you really can have only one broker connection configuration auto-configured. If you would like to have an another similar in the same application, then you should forget that auto-configuration feature. You still can use the mentioned application.properties, but you have to manage them manually.
Since you talk about a RabbitMQ connection, so you need to exclude RabbitAutoConfiguration and manage all the required beans manually:
#SpringBootApplication(exclude = RabbitAutoConfiguration.class)
You still can use the #EnableConfigurationProperties(RabbitProperties.class) on some your #Configuration class to be able to inject that RabbitProperties and populate respective CachingConnectionFactory. For the second broker you can introduce your own #ConfigurationProperties or just configure everything manually reading properties via #Value. See more info about manual connection factory configuration in Spring AMQP reference manual: https://docs.spring.io/spring-amqp/docs/2.2.1.RELEASE/reference/html/#connections

emq and Spring AMQP

I am new to both Spring AMQP and MQTT world. I have a legacy application which uses Rabbitmq as broker for mqtt messages.There are plans to use emqtt as broker and I want to know if my existing listeners ( on mqtt topics) written using Spring AMQP can work with emqtt or not ? I am just trying to save the effort of rewriting all those listeners using MqttClient.
Thanks in advance.

Spring Integration - ActiveMQ to Kafka

I am currently trying to write an adapter which will consume messages from ActiveMQ and publish it to Kafka.
I am thinking of using spring integration to integrate these two messaging systems.
My problem is that my application will not maintain registry of the Models using which many applications will publish the records to activeMQ. I want to receive these javax jms message and want to perform some transformation like adding jmscorrelationId into kafka message.
ALso, another requirement is to send acknowledgement to active mq only when kafka send/publish is successfull.
Can ack be send back to activemq using spring integration?
Will spring integration be a good option?
Kindly note my tech architect is not in favor of using Camel/Mule. Also, he does not want to use Kafka Connect as i was planning to use Kafka connect source.
Please suggest.
The Spring Integration Kafka extension project has a sync mode for publishing, which will block the thread until Kafka confirms delivery (or throw an exception on a failure).
The JMS inbound gateway can be used to return a reply to a JMS queue.
You can add transformers (or whatever) in the flow to modify the message.

link spring integration channel to hornetq

This seems to be simple but I can't work it out.
I am using spring-boot 1.2.2. I have a hornet queue setup in application.properties:
spring.hornetq.mode=embedded
spring.hornetq.embedded.enabled=true
spring.hornetq.embedded.queues=myQueue
I have imported the integration-context.xml file.
#ImportResource("integration-context.xml")
And have defined the following activator:
<int:service-activator
input-channel="myQueue"
ref="myEndpointImpl"
method="send" >
</int:service-activator>
But when I put a message on myQueue the send method is not fired.
What am I doing wrong?
HornetQ is JMS Broker and having that configuration you just provide an embedded mode with one myQueue definition, which is created by Boot on application start up. See more info in the Spring Boot Manual.
Spring Integration allows to work with JMS through the appropriate adapters.
So, if you are going to listen to that HornetQ myQueue using Spring Integration and do some further integration flow you really should configure <int-jms:message-driven-channel-adapter> for that queue and go ahead with your <service-activator> etc. afterwards.
Feel free to ask more questions.

Check if the jms queue is up

Is there a way catch that time-out and send it back to user?
Not sure if Apache Camel provides something out of the box.
I want to test and alert the user which queues are up and running. So that it will be clear to user that which functionality of the application will work or not.
I am using both Spring and Apache Camel in my project.
Ah! I found out. Camel has an out of the box solution.
Camel 2.1: Specifies whether to test the connection on startup. This ensures that when Camel starts that all the JMS consumers have a valid connection to the JMS broker. If a connection cannot be granted then Camel throws an exception on startup. This ensures that Camel is not started with failed connections. From Camel 2.8 onwards also the JMS producers is tested as well.

Resources