我正在使用ActiveMQ Artemis 2.19.1和CORE管理API(org. apache.tivemq.artemis.api.core.client.*
和org.apache.activemq.artemis.api.core.management.*
)从一些前缀队列中获取消费者计数。如果计数等于零,则后端会做一些事情。这是通过定期向代理询问此信息的计划任务完成的。
对于每个请求,都会在后台创建一个临时地址,并在使用信息后将其删除。
问题是Artemis/Hawtio Web控制台的树不断刷新使UI迟缓,并且无法维护。Hawtio已经暗示了这种行为(参见标题为“树不断刷新使UI迟缓”的小节)。
据我所知,CORE api能够处理集群的不同节点,这与Jolokia相比要费力得多。我认为这是使用它的主要原因。
是否有其他可能来处理这个问题?也许是某种连接/会话池?或者如果消费者计数为零,代理可以与后端通信?或者可以批量删除临时队列,而不是一次删除每个队列?
这是日志一次又一次地说:
[org.apache.activemq.artemis.core.server.plugin.impl] AMQ841007: created queue: QueueImpl[name=activemq.management.96a1005f-b67c-40af-b9cd-811f36750c5e, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::name=artemis-2.19.1], temp=true]@58d1994e
[org.apache.activemq.artemis.core.server.plugin.impl] AMQ841008: destroyed queue: QueueImpl[name=activemq.management.96a1005f-b67c-40af-b9cd-811f36750c5e, postOffice=PostOfficeImpl [server=ActiveMQServerImpl::name=artemis-2.19.1], temp=true]@58d1994e, with args address: activemq.management.96a1005f-b67c-40af-b9cd-811f36750c5e, session: ServerSessionImpl(), checkConsumerCount: true, removeConsumers: false, autoDeleteAddress: true
对于我正在使用的连接,如下所示:
private ServerLocator locator;
private ClientSessionFactory defaultFactory;
public ManagementHelper(String defaultURL) {
this.locator = ActiveMQClient.createServerLocator(defaultURL);
this.defaultFactory = locator.createSessionFactory();
}
@Scheduled(fixedRateString = "20000")
public void getConsumerNbos(ClientSessionFactory factory, ServerLocator locator) {
try (ClientSession session = factory.createSession(this.username, this.password, false, true, true,
locator.isPreAcknowledge(), locator.getAckBatchSize());
ClientRequestor requestor = new ClientRequestor(session, "activemq.management");) {
ClientMessage message = session.createMessage(false);
ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, listAllConsumersAsJSON);
session.start();
ClientMessage replyConsumer = requestor.request(message);
String resultJSON = (String) ManagementHelper.getResult(replyConsumer, String.class);
ClientMessage message2 = session.createMessage(false);
ManagementHelper.putOperationInvocation(message2, ResourceNames.BROKER, MANAGEMENT_OPERATION_QUEUES);
ClientMessage replyQueueNames = requestor.request(message2);
Object[] objQueueNames = (Object[]) ManagementHelper.getResult(replyQueueNames);
} catch (Exception e) {
}
}
需要明确的是,日志表明正在创建和销毁队列,而不是地址。
队列正在创建和销毁,因为您使用的是org. apache.actiemq.artemis.api.core.client.ClientRequest estor
。当您创建ClientRequest estor
时,它会自动创建一个临时队列,并在您指定的地址上UUID(例如activemq.management
)。然后,当您关闭ClientRequest estor
时,它会删除此队列。
我的建议是简单地缓存您的ClientSession
和您的ClientRequest estor
,就像您对ServerLocator
和ClientSessionFactory
所做的那样,例如:
private ServerLocator locator;
private ClientSessionFactory defaultFactory;
private ClientSession session;
private ClientRequestor requestor;
public ManagementHelper(String defaultURL) {
this.locator = ActiveMQClient.createServerLocator(defaultURL);
this.defaultFactory = locator.createSessionFactory();
this.session = factory.createSession(this.username, this.password, false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize());
this.requestor = new ClientRequestor(session, "activemq.management");
}
@Scheduled(fixedRateString = "20000")
public void getConsumerNbos(ClientSessionFactory factory, ServerLocator locator) {
ClientMessage message = session.createMessage(false);
ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, listAllConsumersAsJSON);
session.start();
ClientMessage replyConsumer = requestor.request(message);
String resultJSON = (String) ManagementHelper.getResult(replyConsumer, String.class);
ClientMessage message2 = session.createMessage(false);
ManagementHelper.putOperationInvocation(message2, ResourceNames.BROKER, MANAGEMENT_OPERATION_QUEUES);
ClientMessage replyQueueNames = requestor.request(message2);
Object[] objQueueNames = (Object[]) ManagementHelper.getResult(replyQueueNames);
}