Receiving JSON Events via JMS
Purpose¶
This application demonstrates how to configure WSO2 Integrator: SI Tooling to receive events to the SweetProductionStream via Jms transport in Json format using default mapping and log the events in LowProductionAlertStream to the output console.
Prerequisites¶
- Setup ActiveMQ
- Download activemq-client-5.x.x.jar.
- Download apache-activemq-5.x.x-bin.zip
- ActiveMQ
activemq-client-5.x.x.jarshould be added to<SI-Tooling-Home>/libafter being converted to OSGI (See Note: To convert ActiveMQ lib to OSGI). - Unzip the
apache-activemq-5.x.x-bin.zipand copy the following ActiveMQ libs inapache-activemq-5.x.x/libto<SI-Tooling-Home>/samples/sample-clients/liband<SI-Tooling-Home>/lib.- hawtbuf-1.9.jar
- geronimo-j2ee-management_1.1_spec-1.0.1.jar
- geronimo-jms_1.1_spec-1.1.1.jar
- Save this sample.
-
If there is no syntax error, the following message is shown on the console:
Siddhi App ReceiveJMSInJsonFormat successfully deployed.
Note¶
To convert ActiveMQ lib to OSGI,
-
Navigate to
/bin and run the following command: - For Linux:
./icf-provider.sh org.apache.activemq.jndi.ActiveMQInitialContextFactory <Downloaded Jar Path>/activemq-client-5.x.x.jar <Output Jar Path>- For Windows:
./icf-provider.bat org.apache.activemq.jndi.ActiveMQInitialContextFactory <Downloaded Jar Path>\activemq-client-5.x.x.jar <Output Jar Path>- Provide privileges if necessary using
chmod +x icf-provider.(sh|bat). - Also, this will register the
InitialContextFactoryimplementation according to the OSGi JNDI spec. - If converted successfully then it will create
activemq-client-5.x.xdirectory in the<Output Jar Path>with OSGi converted and original jars: activemq-client-5.x.x.jar(Original Jar)activemq-client-5.x.x_1.0.0.jar(OSGi converted Jar)
Also, following messages would be shown on the terminal
- INFO: Executing 'jar uf <absolute_path>/activemq-client-5.x.x/activemq-client-5.x.x.jar -C <absolute_path>/activemq-client-5.x.x /internal/CustomBundleActivator.class' [timestamp] org.wso2.carbon.tools.spi.ICFProviderTool addBundleActivatorHeader - INFO: Running jar to bundle conversion [timestamp] org.wso2.carbon.tools.converter.utils.BundleGeneratorUtils convertFromJarToBundle - INFO: Created the OSGi bundle activemq_client_5.x.x_1.0.0.jar for JAR file <absolute_path>/activemq-client-5.x.x/activemq-client-5.x.x.jar -
You can find the osgi converted libs in
activemq-client-5.x.xfolder. You can copyactivemq-client-5.x.x/activemq-client-5.x.x_1.0.0.jarto<SI-Tooling-Home>/libandactivemq-client-5.x.x/activemq-client-5.x.x.jarto<SI-Tooling-Home>/samples/sample-clients/lib.
Executing the sample¶
- Navigate to
{apache-activemq-5.x.x}unzipped directory. -
Provide required permissions by executing,
chmod +x bin/activemq -
Create system wide configuration defaults, by executing,
sudo bin/activemq setup /etc/default/activemq -
Start ActiveMQ server node using 'bin/activemq start'.
- Start the Siddhi application by clicking on 'Run'.
-
If the Siddhi application starts successfully, the following messages are shown on the console:
ReceiveJMSInJsonFormat.siddhi - Started Successfully!
Testing the sample¶
Navigate to <SI-Tooling-Home>/samples/sample-clients/jms-producer and run ant command without arguments.
Viewing the results¶
Messages similar to the following would be shown on the editor console.
- INFO {io.siddhi.core.stream.output.sink.LogSink} - ReceiveJMSInJsonFormat : OutputStream : Event{timestamp=1513617090756, data=[Cream Sandwich, 790.7842348407036], isExpired=false}
@App:name('ReceiveJMSInJsonFormat')
@App:description('Receive events via JMS provider in JSON format with default mapping and view the output on the console.')
@source(type='jms',
factory.initial='org.apache.activemq.jndi.ActiveMQInitialContextFactory',
provider.url='tcp://localhost:61616',
destination='jms_result_topic',
connection.factory.type='topic',
connection.factory.jndi.name='TopicConnectionFactory',
transport.jms.SubscriptionDurable='true',
transport.jms.DurableSubscriberClientID='wso2SPclient1',
@map(type='json'))
define stream SweetProductionStream(name string, amount double);
@sink(type='log')
define stream LowProductionAlertStream(name string, amount double);
@info(name='EventsPassthroughQuery')
from SweetProductionStream
select *
insert into LowProductionAlertStream;