Send JMS message to Kafka topic via Spring Integration - spring-integration

I am new to Spring Integration and I'm stuck at understanding how it works. What I want to do is receive a message from JMS and then send it to specific Kafka topic. It's very simple and the flow looks like this:
JMS -> My Application -> Kafka
I added spring-integration-kafka and spring-integration-jms dependencies to my application and experimented in creating lots of different IntegrationFlows with different configurations, but nothing seems to be working. Can you please share some pieces of code on how to achieve what I want to do?

Related

Difference between Spring Inbound channel adapters and application event listing message producers

I am working on a POC using Spring Integration and STOMP. The initial POC is successful.
I followed the adapters configuration mentioned in https://docs.spring.io/spring-integration/reference/html/stomp.html#stomp
In my POC, I did not include the last two #Bean definitions from the above link.
Inbound Channel Adapter and Message Handlers were sufficient to handle the incoming messages.
Now, my question is:
What is the difference between Inbound channel adapters and application event listing message producers?
Is ApplicationListener used when we follow DSL as mentioned in an example here?
Thanks,
Mahesh
Well, as you noticed in that Spring Integration documentation about STOMP support there is some bunch of ApplicationEvents emitted by STOMP Channel Adapters. You indeed can handle them using regular ApplicationListener (#EventListener) if your logic for handling those events is pretty much simple and doesn't need further distribution. But if your logic is much complicated and you may need store an even (or its part) in some database, or send via email, do that in parallel after some aggregtion, etc., then indeed that ApplicationEventListeningMessageProducer is much better solution when we have Spring Integration on board already.
However if you talk about a StompInboundChannelAdapter nature and relationship with those mentioned events, you need to take a look into the StompIntegrationEvent implementations. You quickly realize that there is no events for payload in the STOMP frame. So, that is what is done really by the StompInboundChannelAdapter - it produces messages based on the body from STOMP frame.
All the mentioned events emitted fro that channel adapter are more about that adapter state sharing for possible management in your application.

Spring integration - Difference between AmqpOutboundEndpoint and RabbitTemplate

i am trying to write my first AMQP publisher via spring integration using an instance of AmqpOutboundEndpoint.
I don't understand what is the difference between RabbitTemplate and AmqpOutboundEndPoint since AmqpOutboundEndpoint is using an instance of RabbitTemplate.
I would like to use an AMQP gateway to separate 2 different components of my application (Business component and Integration component)
Is it valid to use an AqmpOutboundEndPoint to publish a message when i need to switch the routing key according to the published message type? All examples i found in internet are using a hardcoded routing key for the AMQP gateway.
Thanks
Well, welcome to the Enterprise Integration Patterns
So, first of all you are right, AmqpOutboundEndpoint is really fully based on the RabbitTemplate because it is a good implementation for sending messages over AMQP.
On the other hand the endpoint is a Channel Adapter to receive messages via internal Integration channel.
So, you have to decide for yourself if you really need the whole Integration solution or just sending to the AMQP from your own code is enough.
That endpoint allows you to determine routingKey at runtime against requestMessage using SpEL.
See documentation on the matter: http://docs.spring.io/spring-integration/docs/4.3.11.RELEASE/reference/html/amqp.html#amqp-inbound-ack

Send data to a Channel from a callback method (Spring Integration)

I have a method that is called as a callback from some communication library when data are received.
Using Spring Integration, I would like to send data to a specific Channel that will be later picked up by some Sender and some Database Recorder. These two may work in parallel. How could I do it?
I prefer not to use XML for anything.
These two may work in parallel.
For this purpose Spring Integration provides PublishSubscribeChannel. With its executor option you really can make subscribers working in parallel.
I would like to send data to a specific Channel
So, just do that from that callback method.
You can consider to use Messaging Gateway for dependency injection instead of direct channel injection for sending.
That way you will call the gateway's method from that callback and the data will be send to predefined PublishSubscribeChannel channel for distribution between its subscribers.
how do I create that "existing channel"
That's all about Spring and its inversion of control implementation.
You may consider to consult existing Spring Integration Samples for ideas.

Moving Mail Messaged with Spring Integration

I 'm doing mail processing with spring-integration. I got the receiving part working, but I would like to move the messages to different folders after processing.
Unfortunately, the MimeMessages received from the Adapter are not 'real' javax.mail.Message, but an IntegrationMimeMessage (in AbstractMailReceiver)
Is there a way to access the 'javax.mail.Message' so that I can move them with plain JavaMail? Or does spring-integration provide an adapter that can move messages ? Could not find any in the documentation.

Node and MQTT, do something on message

I am building a specific device based on Node, Cylon and am publishing events to a MQTT broker. I'd like to know how to perform a certain action once a certain MQTT message comes to the device. Can anybody point me in the right direction? I'm a bit lost in the matter ;)
I use this to publish data:
mqtt.publish(thingTopic, JSON.stringify(data));
I'd like to create something like this:
if certain message arrives at broker -> do a post or get request to internal url.
The question is a bit vague, i must admit...
You would probably need to build your own custom MQTT broker to achieve what you are looking for which is not really the point of the pub/sub message paradigm. Instead of customizing the MQTT broker, look into creating your own subscribing application that will react to messages being received from the MQTT Broker.
Hopefully the following sequence diagram will help understand.

Resources