【问题标题】:How can I set expiration for Queues in Activemq if user not subscribed in specific period of time?如果用户在特定时间段内未订阅,如何在 Activemq 中设置队列的过期时间?
【发布时间】:2018-07-07 08:58:47
【问题描述】:

如果用户未订阅,我如何从 activeMQ 中删除队列,我的系统中有很多用户,所以我认为如果用户未从 activeMQ 中删除,将会是性能问题,我使用的是 spring boot 和 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();
        }


}

【问题讨论】:

    标签: spring spring-boot activemq stomp spring-websocket


    【解决方案1】:

    在代理配置中有一个destination policy

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

    【讨论】:

    • 如何在我的 Spring Boot 应用程序中添加这部分,我也在使用 WebSocketConfig
    • ` @Override public void configureMessageBroker(MessageBrokerRegistry config) { config.setApplicationDestinationPrefixes("/app") .setUserDestinationPrefix("/user") .enableStompBrokerRelay("/topic","/queue"," /user") .setRelayHost("localhost") .setRelayPort(61613); }`
    • 请给我一个例子来实现这个
    • 你能看看这个问题吗:stackoverflow.com/questions/49778137/…
    猜你喜欢
    • 2022-06-10
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 2017-10-20
    • 1970-01-01
    • 2021-07-10
    相关资源
    最近更新 更多