このコンテンツは選択した言語では利用できません。

Chapter 3. Getting Started


This chapter guides you through a simple exercise to help you get started using AMQ C++. Before starting, make sure you have completed the steps in the Chapter 2, Installation chapter for your environment.

3.1. Preparing the Broker

The example programs require a running broker with a queue named examples. Follow these steps to define the queue and start the broker.

  1. Install the broker.
  2. Create a broker instance. Enable anonymous access.
  3. Start the broker instance and check the console for any critical errors logged during startup.

    $ BROKER_INSTANCE_DIR/bin/artemis run
    [...]
    14:43:20,158 INFO  [org.apache.activemq.artemis.integration.bootstrap] AMQ101000: Starting ActiveMQ Artemis Server
    [...]
    15:01:39,686 INFO  [org.apache.activemq.artemis.core.server] AMQ221020: Started Acceptor at 0.0.0.0:5672 for protocols [AMQP]
    [...]
    15:01:39,691 INFO  [org.apache.activemq.artemis.core.server] AMQ221007: Server is now live
  4. Use the artemis queue command to create a queue called examples.

    $ BROKER_INSTANCE_DIR/bin/artemis queue create --name examples --auto-create-address --anycast

    You are prompted to answer a series of questions. For yes|no questions, type N; otherwise, press Enter to accept the default value.

3.2. Building the Examples

This section illustrates how to compile the example programs that come with the client API.

  1. Create a directory to hold the programs. This example will call it "AMQ7C++SmokeTest", but you can use any name you like.

    $ mkdir AMQ7C++SmokeTest
  2. Enter the new directory.

    $ cd AMQ7C++SmokeTest
  3. Copy all the examples to this directory.

    $ cp -r /usr/share/proton-0.18.0/examples/cpp .
    Note

    The example directory name depends on the version of proton we just installed - 0.18.0 is the version as of the writing of this documentation. If a different version is actually installed, this directory name will need to be changed to reflect the actual name installed on the system.

    This example compiles all of the examples and will then run the two of interest. They can be compiled like this:

    $ cmake .
    $ make
    Note

    It is not recommended to use cmake in the same directory as the source being built. This example does so for simplicity.

    Consider creating a directory for builds and run cmake there.

3.3. Sending and Receiving Messages

The compiled example programs will use the broker we started earlier to queue the messages between sending and receiving.

Sending Messages

  • Use one of the example programs to send 10 messages to a queue called examples.

    $ ./simple_send -m 10

    The command line option -m 10 tells the program to send 10 messages.

    This will output:

    all messages confirmed
    $

    By default the simple_send example connects to an AMQP listener on the same machine (IP address 127.0.0.1, port 5672) and sends messages to the AMQP address examples. This corresponds to the examples queue that we have configured in the AMQ Broker.

Receiving Messages

  • Execute the following commands as you did in the previous example.

    $ ./simple_recv -m 10

    In this case the command line option -m 10 tells the program to exit after receiving 10 messages.

    simple_recv listening on 127.0.0.1:5672/examples
    {"sequence"=1}
    {"sequence"=2}
    {"sequence"=3}
    {"sequence"=4}
    {"sequence"=5}
    {"sequence"=6}
    {"sequence"=7}
    {"sequence"=8}
    {"sequence"=9}
    {"sequence"=10}
    $

    The simple_recv example is similar to the simple_send example. It also connects to an AMQP listener on the same machine. By default it will subscribe to the AMQP address examples and it will receive 100 messages.

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.