我正在使用ActiveMQ Artemis 2.17.0。我想通过核心API从Java客户端更改路由类型存在队列。我试过了:
...
QueueSession session = createSession(connection)
Message message = session.createMessage();
final QueueConfiguration queueConfiguration = new org.apache.activemq.artemis.api.core.QueueConfiguration('testQueue');
queueConfiguration.setRoutingType(org.apache.activemq.artemis.api.core.RoutingType.MULTICAST);
queueConfiguration.setAddress('testQueue');
queueConfiguration.setAutoCreateAddress(true);
JMSManagementHelper.putOperationInvocation(message, 'testQueue', 'updateQueue', queueConfiguration.toJSON());
Message reply = requestor.request(message);
我收到这个错误:
AMQ229069: no operation updateQueue/1
此外ClientSession
有createQueue
和deleteQueue
方法,但没有updateQueue
方法。如何从客户端API更改队列?
我找到了一个解决方案。首先,创建一个具有2种路由类型的地址,例如:
ClientSession session ...
...
session.createAddress(SimpleString.toSimpleString('testAddress'), EnumSet.allOf(RoutingType.class), false);
接下来,使用此地址创建队列:
final QueueConfiguration queueConfiguration = new QueueConfiguration('testQueue');
queueConfiguration.setRoutingType(RoutingType.ANYCAST);
queueConfiguration.setAddress('testAddress');
queueConfiguration.setAutoCreateAddress(false);
session.createQueue(queueConfiguration);
并且正是在这个队列可以更改路由类型
Queue managementQueue = session.createQueue(MANAGEMENT_QUEUE);
requestor = new QueueRequestor(session, managementQueue);
connection.start();
Message message = session.createMessage();
JMSManagementHelper.putOperationInvocation(message, 'broker', 'updateQueue', 'testQueue', 'MULTICAST', 2, false);
Message reply = requestor.request(message);