8.3. 共有サブスクリプションの作成
共有サブスクリプションとは、1 つ以上のメッセージレシーバーを表すリモートサーバーの状態のことです。このサブスクリプションは共有されているため、複数のクライアントが同じメッセージのストリームから消費できます。
クライアントは、受信者のソースにshared
機能を設定して、共有サブスクリプションを設定します。
共有サブスクリプションは、クライアントコンテナー ID とレシーバー名を組み合わせてサブスクリプション ID を形成することで一意に識別されます。複数のクライアントプロセスで同じサブスクリプションを特定できるように、これらに安定した値を指定する必要があります。shared
に加えて global
機能が設定されている場合、サブスクリプション識別に受信者名だけが使用されます。
永続サブスクリプションを作成するには、以下の手順に従います。
接続コンテナー ID を
client-1
などの安定した値に設定します。proton::container cont {handler, "client-1"};
proton::container cont {handler, "client-1"};
Copy to Clipboard Copied! Toggle word wrap Toggle overflow sub-1
などの安定した名前で受信者を作成し、shared
機能 を設定して共有用に受信者のソースを設定します。void on_container_start(proton::container& cont) override { proton::connection conn = cont.connect("amqp://example.com"); proton::receiver_options opts {}; proton::source_options sopts {}; opts.name("sub-1"); sopts.capabilities(std::vector<proton::symbol> { "shared" }); opts.source(sopts); conn.open_receiver("notifications", opts); }
void on_container_start(proton::container& cont) override { proton::connection conn = cont.connect("amqp://example.com"); proton::receiver_options opts {}; proton::source_options sopts {}; opts.name("sub-1"); sopts.capabilities(std::vector<proton::symbol> { "shared" }); opts.source(sopts); conn.open_receiver("notifications", opts); }
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
サブスクリプションからデタッチするには、proton::receiver::detach()
メソッドを使用します。サブスクリプションを終了するには、proton::receiver::close()
メソッドを使用します。
詳細は、shared-subscribe.cpp の例 を参照してください。