解决方法:需要设置subscriptionName参数,并指定unique持久订阅名称。示例代码如下:
//创建STOMP连接工厂
StompConnectionFactory stompConnectionFactory = new StompConnectionFactory();
stompConnectionFactory.setBrokerURI("tcp://localhost:61616");
//创建STOMP连接
StompConnection stompConnection = stompConnectionFactory.createConnection();
stompConnection.start();
//创建STOMP会话
StompSession stompSession = stompConnection.connect().getSession();
//订阅STOMP消息
stompSession.subscribe(destination, new CustomStompFrameHandler(), new SubscriptionOptions(Stomp.Headers.Subscribe.AckModeValues.AUTO));
//此处设置subscriptionName参数
SubscriptionOptions subscriptionOptions = new SubscriptionOptions();
subscriptionOptions.setSubscriptionName("unique-persistent-subscription");
stompSession.subscribe(destination, new CustomStompFrameHandler(), subscriptionOptions);