私はチェックがclustered-static-discovery、またudpベースのクラスタリング クラスタに2つのノードがある場合は2つの接続が必要ですメッセージをラウンドロビンで消費するためには4つの接続が必要です。Apache artemisは多くの接続をSTRICTの設定で多くのサーバーノードを作成する必要があります
1つの接続またはリスナーしか作成していない場合、2つのサーバーに2つの接続があり、10のメッセージが生成され、5つのメッセージが欠落するとします。
多くの接続を作成する代わりに、1つの接続でメッセージを受信する方法(使用されるサーバーノードの数によって異なります)。 が実行時間のノードが追加シナリオがあるので、ここで時間追加したノード
を実行するために来るそれらのメッセージを欠場するので、私は(クラスタ内での)2つのノードと1つの接続
import javax.jms.*;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.core.client.impl.ClientSessionInternal;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.util.ServerUtil;
/**
* A simple example that demonstrates server side load-balancing of messages between the queue instances on different
* nodes of the cluster. The cluster is created from a static list of nodes.
*/
public class StaticClusteredQueueExample {
public static void main(final String[] args) throws Exception {
Connection connection0 = null;
try {
Topic topic = ActiveMQJMSClient.createTopic("exampleTopic");
ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:9616");
Thread.sleep(2000);
connection0 = cf0.createConnection();
final String clientID = "admin";
connection0.setClientID(clientID);
final String subscriptionName = "mySub";
Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection0.start();
MessageConsumer subscriber0 = session0.createDurableSubscriber(topic, subscriptionName);
Thread.sleep(2000);
MessageProducer producer = session0.createProducer(topic);
// We send 20 messages to server
final int numMessages = 20;
for (int i = 0; i < numMessages; i++) {
TextMessage message = session0.createTextMessage("This is text message " + i);
producer.send(message);
System.out.println("Sent message: " + message.getText());
}
Thread.sleep(2000);
for (int i = 0; i < numMessages; i += 2) {
try {
TextMessage message0 = (TextMessage) subscriber0.receive(5000);
System.out.println("" + message0.getText() + ": from node " + ServerUtil.getServer(connection0));
} catch (Exception e) {}
}
} finally {
// Step 15. Be sure to close our resources!
if (connection0 != null) {
connection0.close();
}
}
}
}
を持っている例です。 上記の例で
生産 によって20メッセージを送信するが、私はそれだけthe clustering documentation状態として代わりに20
ロードバランシングはサーバ側で動作していますが、これは問題ではありません。 問題はSTRICTを使用するとサーバ側でロードバランスが取られるということです。クラスタ内でSTRICTを使用する2つのノードがあり、クラスタ内のSTRICTを変更することなく、1つの接続のみを使用してメッセージを消費する可能性があります。 – Baba
いいえ。メッセージロードバランシングがSTRICTとして構成されている場合、単一ノードへの接続からクラスタ内の特定のキューのすべてのメッセージを消費することはできません。メッセージの再配布は、メッセージロードバランシングがドキュメントの状態に応じてON_DEMANDとして構成されている場合にのみ発生します。 –