Contents
- Introduction
- Running the RabbitMQ HelloWorld Sample in StreamBase Studio
- Running the RabbitMQ Work Queues Sample in StreamBase Studio
- Running The RabbitMQ Publish/Subscribe Sample in StreamBase Studio
- Running the RabbitMQ Routing Sample in StreamBase Studio
- Running the RabbitMQ Topics Sample in StreamBase Studio
- Running the RabbitMQ Remote Procedure Call (RPC) Sample in StreamBase Studio
- Running the RabbitMQ CustomSerializer Sample in StreamBase Studio
- Running The RabbitMQ Ack and Nack Sample in StreamBase Studio
- Importing This Sample into StreamBase Studio
- Sample Location
This topic describes how to run the RabbitMQ adapters sample applications, which illustrate how to use the RabbitMQ adapters when connecting a StreamBase application to a RabbitMQ server. The samples were built to replicate the tutorials that are found on the RabbitMQs website.
Before running any of the samples you must first edit the sbd.sbconf
file and enter the correct connection information to your RabbitMQ server
Note
Keep in mind that the current adapters were built on top of the 3.6.0 version of the RabbitMQ client library.
All the samples provided create queues and exchanges that are set to auto delete on disconnect. This was done to reduce and clutter on your server from running the sample.
This sample demonstrates how to implement the HelloWorld Tutorial from the RabbitMQ website.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
HelloWorld.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Application Output view, examine the output and see that the message you entered has now been output via the ConsumerData output stream.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how to implement the Work Queues Tutorial from the RabbitMQ website.
This sample shows how to send time-consuming task among multiple works. Note that the number of instances of the consumer
represent the number of available workers; in the sample it is set to two. This sample uses a main module, WorkQueues.sbapp
and a submodule, WorkQueuesConsumer.sbapp
. The submodule contains the consumer code and the main module uses the submodule with multiplicity enabled to run multiple
instances of the same event flow which enables multiple consumers.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
WorkQueues.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.The
message
field is a list of strings. Add one or two strings to the list (each string is meant to simulate one second of consumer work time).Click
. -
In the Application Output view, examine the output and see that the message you entered is now output to the ConsumerData output stream.
Also notice the ConsumerAckStatus shows that a successful acknowledgment of the message was sent after the data was processed.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how to implement the Publish/Subscribe Tutorial from the RabbitMQ website.
This sample shows how to send a message to multiple consumers.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
PublishSubscribe.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output to the Consumer1Data and Consumer2Data output streams, showing that each consumer received the message.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how to implement the Routing Tutorial from the RabbitMQ website.
This sample shows how to subscribe to only to a subset of the messages. The sample shows how to direct messages to a specific subset of consumers.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
Routing.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Enter
error
into theroutingKey
field.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output via the ErrorConsumerData.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Enter
debug
into theroutingKey
field.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output via the DebugConsumerData.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how to implement the Topics Tutorial from the RabbitMQ website.
This sample shows how to send messages based on topics. Messages sent to a topic exchange cannot have an arbitrary route − it must be a list of words, delimited by dots. The words can be anything, but usually they specify some features connected to the message.
In this sample, notice there are four different consumers: two consumers, CriticalTopicsConsumer
and KernTopicsConsumer
, subscribe to a single specific topic end point while MultipleTopicsConsumer
subscribes to multiple, and AllTopicsConsumer
will display all messages by subscribing to #
.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
Topics.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Enter
kern.debug
into theroutingKey
field.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output via MultipleTopicsConsumer MultipleTopicsConsumer, AllTopicsConsumer, and KernTopicsConsumer.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Enter
system.critical
into theroutingKey
field.Click
. -
In the Application Output view, examine the output and see that the message you have entered has now been output via the MultipleTopicsConsumer, AllTopicsConsumer, and CriticalTopicsConsumer.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how to implement the RPC Tutorial from the RabbitMQ website.
This sample shows how to send a message from the client to the server. The server then processes the message performing an operation (in this samples case squaring the number provided) and returning the result.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
RPC.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ClientCall
input stream.Enter an integer value (for example 8) into the
message
field.Click
. -
In the Application Output view, examine the output of the ClientConsumeData stream. Its message is the square number of the one you entered.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how to implement custom serialization of the message data. The sample demonstrates this using a tuple message type and converts the tuple into a JSON value at the producer side to send to the server and then converts that JSON value back into the tuple on the consumer side.
The source files that implement the custom serialization are java-src\com.streambase.rabbitmq.sample\CustomDeserializer.java
and java-src\com.streambase.rabbitmq.sample\CustomSerializer.java
.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
CustomSerializer.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some values into the
message.Field1
andmessage.Field2
fields.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output to the ConsumerData output stream, showing that it was properly serialized.
-
When done, press F9 or click the
Stop Running Application button.
This sample demonstrates how messages can be acknowledged instead of auto-acknowledged. It also demonstrates how a negative acknowledgment works.
The sample is set up so that every second message that is sent to the Consumer2
will be negative acknowledged and sent back to the server to be requeued and picked up by another consumer, which in this
sample can only be Consumer1.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer view, double-click to open the
SampleAckAndNack.sbapp
application. -
Make sure the application is the currently active tab in the EventFlow editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output via the Consumer1Out output stream.
-
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Application Output view, examine the output and see that the message you entered is now output via the Consumer2Out output stream.
In this instance, notice that the
Consumer2NackStatus
shows that a Nack was sent back to the server.You should now see that
Consumer1Out
received the message; also examine itsenvelope.isRedliver
field and notice its value istrue
which means this message was previously delivered but not acknowledged. -
When done, press F9 or click the
Stop Running Application button.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
→ . -
Type
RabbitMQ
to narrow the list of options. -
Select RabbitMQ operators from the Messaging category.
-
Click OK.
StreamBase Studio creates a single project for the RabbitMQ adapter samples in your current Studio workspace.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Important
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_adapter_embedded_RabbitMQ
See Default Installation Directories for the location of studio-workspace
on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/adapter/embedded/rabbitmq
See Default Installation Directories for the default location of studio-workspace
on your system.