如果用户在特定时间段内未订阅,如何在 Activemq 中设置队列的过期时间



如果用户不订阅,如何从activeMQ中删除队列,我在系统中有很多用户,所以我认为如果用户没有从activeMQ中删除,将会是性能问题,我正在使用spring启动和WebSocketConfig,这是我的实现:

@Service
public  class NotificationWebSocketService {
    @Autowired
    private SimpMessagingTemplate messagingTemplate;
    public void initiateNotification(WebSocketNotification notificationData) throws InterruptedException {
        Map<String, Object> headers = new HashMap<>();
        headers.put("expires", System.currentTimeMillis() + 20000);
        messagingTemplate.convertAndSendToUser(notificationData.getUserID(), "/reply", notificationData.getMessage(),headers);
    }
}

@Configuration
@EnableWebSocketMessageBroker 
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
      @Override
        public void configureMessageBroker(MessageBrokerRegistry config) {
          config
            .setApplicationDestinationPrefixes("/app")
            .setUserDestinationPrefix("/user")
            .enableStompBrokerRelay("/topic","/queue","/user")
            .setRelayHost("localhost")
            .setRelayPort(61613);

        }

        public void registerStompEndpoints(StompEndpointRegistry registry) {
            registry.addEndpoint("/websocket").withSockJS();
        }

}

代理配置中有一个目标策略。

<broker xmlns="http://activemq.apache.org/schema/core" schedulePeriodForDestinationPurge="10000">
  <destinationPolicy>
     <policyMap>
        <policyEntries>
           <policyEntry queue=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000"/>
        </policyEntries>
     </policyMap>
  </destinationPolicy>
</broker>

最新更新