Open topic with navigation

# Queuing

Queuing and load balancing are important for an efficient messaging system.

A set of publishing applications sends messages to a queue from which subscribing applications retrieve messages. Run multiple subscribers to increase the throughput of your messaging system by increasing message consumption. Each subscriber acknowledges each message that it has finished processing. This causes the message to be removed from the queue. If an application stops or fails to acknowledge a message it has retrieved from the queue, the message is made available for other applications to retrieve. This ensures that all messages are processed. For more details, see Event Queue and Messaging Dispatch.

In this example, you use these commands in `samples\bin`:

- `tibftlshared-producer`: To write messages to the queue (the publisher)

- `tibftlshared-consumer`: To read the messages in the queue (the subscriber)

Using a single producer and single consumer application, the consumer receives every message the producer sends in the order it was sent.

Perform these steps:

1. Open three terminals. In each, make sure you have run the `setup` command and started the FTL server. See the Command Reference.

2. In one of the terminals, start the producer by running the `tibftlshared-producer` application located in the `samples/bin` directory.

   - Linux and macOS:

         $./tibftlshared-producer localhost:8080

   - Windows:

         >tibftlshared-producer localhost:8080

   The result shows the producer started publishing messages, each with an application-generated sequence number.

    $ tibftlshared-producer localhost:8080## tibftlshared-producer# (FTL) TIBCO FTL Version <n.n>	V<n>## Client name tibftlshared-producer_58777#Sending message sequence 0Sending message sequence 1Sending message sequence 2Sending message sequence 3Sending message sequence 4

1. In another terminal, start the consumer by running the `tibftlshared-consumer` application located in the `samples/bin` directory:

   - Linux and macOS:

         $./tibftlshared-consumer localhost:8080

   - Windows:

         >tibftlshared-consumer localhost:8080

     The result shows a message that has two fields:

     - `string` containing the application name of the producer who sent this message

     - `long` containing the sequence number from that specific producer
       Because only one producer and one consumer is running, the sequence numbers are in order.

    $ tibftlshared-consumer localhost:8080## tibftlshared-consumer# (FTL) TIBCO FTL Version <n.n>	V<n>## Client name tibftlshared-consumer_58804#Waiting for message(s)Received message {string:sender="tibftlshared-producer_58777", long:sequence=0}Received message {string:sender="tibftlshared-producer_58777", long:sequence=1}Received message {string:sender="tibftlshared-producer_58777", long:sequence=2}Received message {string:sender="tibftlshared-producer_58777", long:sequence=3}Received message {string:sender="tibftlshared-producer_58777", long:sequence=4}

1. In the third terminal, start the second consumer so the output of the two consumers doesn’t get interspersed.

## Check Your Result

Typical output from each consumer follows. In this example, each consumer requests a single message, reads from the same queue, and is serviced in a round-robin fashion. The consumers dump the message as a string and acknowledge it. This results in each consumer receiving every other message.

Consumer 1

    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=219}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=221}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=223}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=225}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=227}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=229}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=231}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=233}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=235}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=237}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=239}

Consumer 2

    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=220}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=222}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=224}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=226}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=228}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=230}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=232}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=234}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=236}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=238}
    Received message
    {string:sender="tibftlshared-producer_58777", long:sequence=240}

Typically, you do not see the alternating cadence in the example. A consumer controls how many messages it processes at a time. It can take different amounts of time for a consumer to process and acknowledge the messages.

## Adding More Producers

The following output is from one of three consumers running with messages coming from two producers. The two producers are identified by their different application names:

- `tibftlshared-producer_59154`

- `tibftlshared-producer_59163`

    Received message
    {string:sender="tibftlshared-producer_59154", long:sequence=258}
    Received message
    {string:sender="tibftlshared-producer_59163", long:sequence=148}
    Received message
    {string:sender="tibftlshared-producer_59154", long:sequence=261}
    Received message
    {string:sender="tibftlshared-producer_59163", long:sequence=151}
    Received message
    {string:sender="tibftlshared-producer_59154", long:sequence=264}
    Received message
    {string:sender="tibftlshared-producer_59163", long:sequence=154}
    Received message
    {string:sender="tibftlshared-producer_59154", long:sequence=267}
    Received message
    {string:sender="tibftlshared-producer_59163", long:sequence=157}

You can try different combinations of producers and consumers. Stop and restart them in different scenarios and see how the delivery cadence changes.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO FTL® - Enterprise Edition

Copyright © 2009-2024. Cloud Software Group, Inc. All Rights Reserved.