Contents
- About These Samples
- Importing This Sample into StreamBase Studio
- 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
- Sample Location
This topic describes how to run the TIBCO StreamBase® Adapter for RabbitMQ 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 src/main/resources/adapter-configurations.xml
file and enter the correct connection information to your RabbitMQ server
Note
The adapters are built on top of the 3.6.0 version of the RabbitMQ client library.
The samples create queues and exchanges that are set to auto-delete on disconnect. This was done to reduce and clutter on your server when running the sample.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
→ . -
Type
ra
To narrow the list of options. -
Select rabbitmq from the StreamBase Messaging Adapters category.
-
Click
.
StreamBase Studio creates a single project containing the sample files.
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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
HelloWorld.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Output Streams 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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
WorkQueues.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
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 Output Streams 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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
PublishSubscribe.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Output Streams 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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
Routing.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
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 Output Streams 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 Output Streams 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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
Topics.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
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 Output Streams 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 Output Streams 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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
RPC.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
In the Manual Input view, select the
ClientCall
input stream.Enter an integer value (for example,
8
) into themessage
field.Click
. -
In the Output Streams 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 CustomDeserializer.java
and CustomSerializer.java
, which are located under the project folder in src/main/java
.
The steps to run this sample in Studio are as follows:
-
In the Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
CustomSerializer.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
In the Manual Input view, select the
ProducerIn
input stream.Enter some values into the
message.Field1
andmessage.Field2
fields.Click
. -
In the Output Streams 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 Project Explorer, open the sample you just loaded.
-
Open the
src/main/eventflow
folder. -
Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).
-
Open the
SampleAckAndNack.sbapp
application file and click theRun button. This opens the SB Test/Debug perspective and starts the application.
If you see red marks, wait a moment for the project in Studio to load its features.
If red marks do not resolve themselves in a moment, select the project and right-click
→ from the context menu. -
In the Manual Input view, select the
ProducerIn
input stream.Enter some text into the
message
field.Click
. -
In the Output Streams 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 Output Streams 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.
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 permission problems. The default workspace location for this sample is:
studio-workspace
/sample_adapter_embedded_RabbitMQ
See Default Installation Directories for the default location of studio-workspace
on your system.