Spring Integration between two message brokers - spring-boot

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

Related

Mocking SchemaRegistryClient in stream processor Consumer

I have a Reactor-based Spring Boot Kafka stream processing app that I am working on writing integration tests for. I am using Spring's #EmbeddedKafka broker. It works great, I have it overriding the bootstrap broker urls that get configured on my reactive processor's consumer & publisher, but what I haven't figured out yet is how to deal with the schema registry for my processor when testing. I'm using Confluent's KafkaAvroSerializer and KafkaAvroDeserializer classes and just have the schema.registry.url field configured in my Spring app configs to get injected into the Kafka properties. I'm using Confluent's MockSchemaRegistryClient for the test producer and consumer, but what I need is a way to inject this mock client into the actual consumer and producer in my stream processor code, but I see no way to do that. Almost seems like I need something more like an embedded version of the schema registry to point them to like the embedded broker. Our build pipeline does not support spinning up containers otherwise I'd use Docker or Testcontainers. Anyone else solve this already? Any help or suggestions appreciated.
I managed to figure this out. If you use a url that begins with mock:// for your test's SerDes, and you override the schema.registry.url property in the #SpringBootTest annotation with the same mock url, then your processor's consumer and producer will also pick up and use this mock schema registry client, and everything just works!

Spring Config Server with Spring Boot Properties

I am storing application.properties file in my config server. And my client applications are refering config server to download the property files.
Scenario 1:
When i change the value of property server.port in my config server. Can i reflect the changes in my client applicaiton without restarting the application.
You can use #RefreshScope beans for this purpose, this is not ideal but as close as you can get in config server, this is a pretty advanced thing after all.
So beans marked with this annotations will cause spring to clear the internal cache of the beans / configuration classes upon EnvironmentChangeEvent, then the instance of the bean will be created next time you'll try to call this bean.
To trigger such an event when the config server changes you can either explicitly call the actuator's refresh enpoint or develop your own solution that might be based on some messaging system so that the config server will be a producer of a "change" message and the consumer will be your application.
Now I can't say for sure whether it will work in particular with server.port, I've personally never seen a need to change this property, but for your custom beans this method will do the job.
Here is a good tutorial about this topic

JMS configuration for Spring Integration

I am trying to implement activemq(just want to receive messages) with spring integration.I cant find any clues how to provide java configuration for activemq. What are the minimum required components for job. Somewhere we have channel, adapter somewhere we dont. I am unable to understand spring concepts of adapter, channel and service activator. They are all feeling same to me. I find the integration documentation going above my head. I never had problems with understanding other spring modules(boot, mvc, cloud, batch). Can someone point me in the right direction or what is it that I am doing wrong.
You probably are missing the fact that Spring Integration is a reference implementation for well-known Enterprise Integration Patterns. So, please, consider to start from the theory and ideas. Then you can come back to Spring Integration as an API for those EIP. See respective book on the matter: https://www.enterpriseintegrationpatterns.com.
To read messages from JMS destination you need to use a JmsMessageDrivenEndpoint with respective ConnectionFactory injected.
There is nothing more about that than an ActiveMQConnectionFactory as a bean.
For example in tests we do like this:
new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false")
And an in-memory broker is started.
See a test class with Java DSL for some way how to configure JMS components: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java

In Spring Boot, How do I declare that my JMS server is embedded?

The Spring Boot documentation has this very brief illustration of an embedded JMS server: "Two beans that you don’t see defined are JmsTemplate and ConnectionFactory. These are created automatically by Spring Boot. In this case, the ActiveMQ broker runs embedded." Huh? The Reference Documentation doesn't say a thing about it. I need to create two VMs, each running from its own jar file, and I need one of them to launch an embedded JMS server, but I have no idea how to do this. Can somebody point me in the right direction. (If you provide a link, I would prefer some clear documentation over an example, but I'll be happy with a good example.)
You are looking at the wrong reference documentation. Yours is from Spring Integration.
The one of Spring Boot can be found here:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-activemq
And there you will find the answer:
When ActiveMQ is available on the classpath, Spring Boot can also
configure a ConnectionFactory. If the broker is present, an embedded
broker is automatically started and configured (provided no broker URL
is specified through configuration).

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.

Resources