You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a problem with the load balancing consumers to a jboss cluster. They don't stay connected to the same server over time.
Let's contextualize by our infrastructure :
We have a HornetQ jms broker hosted by two jboss eap6 servers. With artemis client, We connect to our cluster by this url (tcp://jbosshost01:5049,tcp://jbosshost01:5049)?protocolManagerFactoryStr=org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory. All servers have a queue in our cluster, so here two queues. For the load balancing needs or move messages from jbosshost01 to jbosshost01 or reverse, some queues exist between servers to move messages if needed.
The cluster look like below in the best situation. Two servers with two consumer on each. It should be more in production.
Consumer balancing is not stable over a long period of time. They change servers. For example, consider 2 connexion and 4 consumer, the consumer balancing number could be like following :
host 1 host 2
1 3
0 4
3 1
4 0
Sending messages or not, it's the same.
This behavior on the client side is handled by the default class RoundRobinConnectionLoadBalancingPolicy in Artemis Client.
how to keep a consumer connected to a server, no matter how many times a connection and a session are created on the cluster ?
An example of the code that we use inside our consumer.
// this following consumeMessages() method is called by 4 thread in parallel which are run by a scheduler quarkus@Transactional(Transactional.TxType.NEVER)
privatevoidconsumeMessages() throwsJMSException {
log.debug("start session consuming activity");
try (Connectionconnection = factory.createConnection();
Sessionsession = connection.createSession(Session.SESSION_TRANSACTED);
MessageConsumerconsumer = session.createConsumer(queue)) {
connection.start();
varinstant = LocalTime.now();
while (isStillInActivity(instant)) {
varmessage = consumer.receive(MESSAGE_RECEPTION_TIMEOUT.toMillis());
if (message != null) {
log.debug("session thread treat message");
booleanok = false;
try {
listener.onMessage(message);
session.commit();
log.debug("### session commit");
ok = true;
} finally {
if (!ok) {
session.rollback();
log.debug("### session rollback");
}
}
} else {
log.debug("session thread remains idle");
}
}
log.debug("end session activity successfully");
}
}
privatebooleanisStillInActivity(LocalTimeinstant) {
LocalTimetimeout = instant.plus(sessionTTL);
returnLocalTime.now().isBefore(timeout) && !shutdown.get();
}
Thanks !
The text was updated successfully, but these errors were encountered:
Hi @zhfeng
We have a problem with the load balancing consumers to a jboss cluster. They don't stay connected to the same server over time.
Let's contextualize by our infrastructure :
We have a HornetQ jms broker hosted by two jboss eap6 servers. With artemis client, We connect to our cluster by this url
(tcp://jbosshost01:5049,tcp://jbosshost01:5049)?protocolManagerFactoryStr=org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory
. All servers have a queue in our cluster, so here two queues. For the load balancing needs or move messages from jbosshost01 to jbosshost01 or reverse, some queues exist between servers to move messages if needed.The cluster look like below in the best situation. Two servers with two consumer on each. It should be more in production.
Consumer balancing is not stable over a long period of time. They change servers. For example, consider 2 connexion and 4 consumer, the consumer balancing number could be like following :
Sending messages or not, it's the same.
This behavior on the client side is handled by the default class
RoundRobinConnectionLoadBalancingPolicy
in Artemis Client.how to keep a consumer connected to a server, no matter how many times a connection and a session are created on the cluster ?
An example of the code that we use inside our consumer.
Thanks !
The text was updated successfully, but these errors were encountered: