Apache Camel: First IOTA Component Example
INTRODUCTION
I am proud to comunicate that Apache Camel since version 2.24 will support IOTA DLT Component (I'm the author)
Apache Camel is a open source implementation of famous Enterprise Integration Patterns. Camel is a Routing and Mediation Engine and facilitates the developers to create routes and mediation rules in variety of Domain Specific language(DSL) such as java, Spring/XML, Scala etc.
TUTORIAL
Into this blog article i will explain how to create a simple project to send data from MQTT to IOTA Tangle!
Create java project
To create java project you can use maven archetypes
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes \
-DarchetypeArtifactId=camel-archetype-spring -DarchetypeVersion=2.22.0 \
-DarchetypeRepository=https://repository.apache.org/content/groups/snapshots-group
Inside the folder src/main/resources/META-INF/spring can find the main file camel-context.xml
POM dependencies
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mqtt</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-iota</artifactId>
</dependency>
Note: You must upgrade camel version form 2.22.0 to 2.24.0-SNAPSHOT
Write the code
Now is let time to edit the file to write data to the tangle<route>
<from uri="mqtt://test?host=tcp://test.mosquitto.org:1883&subscribeTopicName=fabryprog-iota/test"/>
<setHeader headerName="CamelIOTASeed">
<constant>9HIAWQJHGOPQVPWNCLKNVVMZZCUJXGUXYGJQNVXMWWUWXZUVQDBVAWBEGBPHWMXSYECPGZMJMNYHLQMVN</constant>
</setHeader>
<setHeader headerName="CamelIOTAValue">
<constant>0</constant>
</setHeader>
<setHeader headerName="CamelIOTAToAddress">
<constant>LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC</constant>
</setHeader>
<to uri="iota://fabryprog-iota?url=https://nodes.thetangle.org:443&tag=APACHECAMELIOTA&operation=sendTransfer&depth=3" />
</route>
Now, open terminal and launch the command to camel run
mvn clean camel:run
Send MQTT data
You can send data to mqtt server using a common mqtt clientI use mosquitto-client:
mosquitto_pub -h test.mosquitto.org -t fabryprog-iota/test -m "First Apache Camel Iota Example"
Now you can find my transaction test using tangle explorer (link)
Have fun with Apache Camel IOTA!
GitHub Repo
Apache Camel Official Documentation
Commenti
Posta un commento