이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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
    Copy to Clipboard Toggle word wrap
  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
    Copy to Clipboard Toggle word wrap

    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
    Copy to Clipboard Toggle word wrap
  2. Enter the new directory.

    $ cd AMQ7C++SmokeTest
    Copy to Clipboard Toggle word wrap
  3. Copy all the examples to this directory.

    $ cp -r /usr/share/proton-0.21.0/examples/cpp .
    Copy to Clipboard Toggle word wrap
    Note

    The example directory name depends on the version of proton we just installed - 0.21.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
    Copy to Clipboard Toggle word wrap
    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
    Copy to Clipboard Toggle word wrap

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

    This will output:

    all messages confirmed
    $
    Copy to Clipboard Toggle word wrap

    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
    Copy to Clipboard Toggle word wrap

    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}
    $
    Copy to Clipboard Toggle word wrap

    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은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat