Monday, April 14, 2014

Spring Integration: Mqtt integration and Transformation of the mqtt Message from CSV to Java Bean using int:transformer

Removed

Working with Spring Integration, the use of Mqtt become very easy. In fact we need only to declare an int-mqtt:message-driven-channel-adapter in the applicationContext or spring-integration-context.xml

The code is :



The integration graph looks then like this :

So in order to convert the message coming from the broker (in CSV format), we need to call the method convert in the created CsvConverter class. In order to configure this using int:transformer, we need to declare a spel-function where we specify the class and called method, then we use the Id inside the spEL expression inside the transformer by putting # before the id of the converter.
so here is the code.

<int:spel-function id="csvConverter" class="org.converter.CsvConverter" method="convert(java.lang.String)" />

<int:transformer id="csvTransformer"
input-channel="mqttMessages"
output-channel="record" expression="#csvConverter(payload)" />

So now the transformer will call the CSVConverter which will convert the mqtt message payload from CSV to Java Bean (here Record).  The conversion is done using CSVeed framework which construct the given bean from the csv message.




2 comments :

  1. please explain all step to integrate spring with mqtt

    ReplyDelete
  2. i am developing a chat api for low end device , i am using spring mqtt can you please send me a sample hello world using spring mqtt integration , i am trying but not able to connect with mqtt port

    ReplyDelete

Articles les plus consultés