Publishing XML Events via RabbitMQ¶
Purpose:¶
This application demonstrates how to configure ESB Streaming Integrator Tooling to send sweet production events via RabbitMQ transport in XML format, and view the output on the rabbitmq-consumer.
Prerequisites:¶
- Save this sample. The following message appears on the console.
    
Siddhi App PublishRabbitmqInXmlFormat successfully deployed. - Setting up RabbitMQ broker in Ubuntu Linux.
- To download and install RabbitMQ, run the following commands:
    
sudo apt-get update sudo apt-get install rabbitmq-server - To manage the maximum amount of connections upon launch, open and edit the following configuration file using a nano command:
    
sudo nano /etc/default/rabbitmq-server - To enable RabbitMQ Management Console, run the following command:
    
sudo rabbitmq-plugins enable rabbitmq_management - To start the service, issue the following command:
    
invoke-rc.d rabbitmq-server start 
 - To download and install RabbitMQ, run the following commands:
    
 
Executing the Sample:¶
- Open a terminal and navigate to the 
{WSO2SIHome}/samples/sample-clients/rabbitmq-consumerdirectory and run theantcommand.- If you use the default exchange 
RABBITMQSAMPLEand URIamqp://guest:guest@localhost:5672in your program useantcommand without any arguments. - However, if you use different exchange names or URIs, run the 
antcommand with appropriate arguments. e.g.,ant -Dexchange=rabbitMqtest 
 - If you use the default exchange 
 - Start the Siddhi application by clicking 'Run'.
 - If the Siddhi application starts successfully, the following messages appear on the console.
PublishRabbitmqInXmlFormat.siddhi - Started Successfully! 
Testing the Sample:¶
- Open the event simulator by clicking the second icon or pressing Ctrl+Shift+I.
 - In the Single Simulation tab of the panel, select values as follows:
- Siddhi App Name: PublishRabbitmqInXmlFormat
 - Stream Name: SweetProductiontream
 
 - In the name field and amount fields, enter 'toffee' and '45.24' respectively and then click Send to send the event.
 - Send some more events.
 
Viewing the Results:¶
- See the output in the terminal of 
{WSO2SIHome}/samples/sample-clients/rabbitmq-consumer. You will get the output as follows (sample output for 4 events):[java] [org.apache.axiom.om.util.StAXUtils] : XMLStreamReader is org.apache.axiom.util.stax.dialect.SJSXPStreamReaderWrapper [java] [io.siddhi.core.stream.output.sink.LogSink] : PublishRabbitmqInXmlFormatTest : logStream : Event{timestamp=1512448790922, data=[toffee, 9.78], isExpired=false} [java] [org.apache.axiom.om.util.StAXUtils] : XMLStreamReader is org.apache.axiom.util.stax.dialect.SJSXPStreamReaderWrapper [java] [io.siddhi.core.stream.output.sink.LogSink] : PublishRabbitmqInXmlFormatTest : logStream : Event{timestamp=1512448813975, data=[lollipop, 12.6], isExpired=false} [java] [org.apache.axiom.om.util.StAXUtils] : XMLStreamReader is org.apache.axiom.util.stax.dialect.SJSXPStreamReaderWrapper [java] [io.siddhi.core.stream.output.sink.LogSink] : PublishRabbitmqInXmlFormatTest : logStream : Event{timestamp=1512448830488, data=[Pop, 72.6], isExpired=false} 
Notes:¶
If you need to edit this application while it is running, stop the application -> Save -> Start.
If the message 'LowProducitonAlertStream' stream could not connect to 'localhost:5672', it could be due to port 5672, which is defined in the Siddhi application. This port is already being used by a different program. To resolve this issue, please do the following,
* Stop this Siddhi application (click 'Run' on menu bar -> 'Stop').
* Change the port 5672 to an unused port.
* Start the application and check whether the expected output appears on the console.
RabbitMq consumer was written according to this example (go through the RabbitMQReceiver application).
@App:name("PublishRabbitmqInXmlFormat")
@APP:description("demonstrates how to configure ESB Streaming Integrator Tooling to send sweet production events via RabbitMQ transport in XML format, and view the output on the rabbitmq-consumer")
define stream SweetProductionStream (name string, amount double);
@sink(type ='rabbitmq', uri = 'amqp://guest:guest@localhost:5672', exchange.name = 'RABBITMQSAMPLE',
    @map(type='xml'))
define stream LowProducitonAlertStream (name string, amount double);
from SweetProductionStream
select *
insert into LowProducitonAlertStream;
                
                  
                
              
Top