0

I want to control stomp subscription in my Spring application with spring-messaging v.4.2. This is my Spring app configuration for stomp:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.myapp")
@EnableWebSocketMessageBroker
@EnableAsync
@EnableScheduling
public class Config extends AbstractWebSocketMessageBrokerConfigurer  {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/queue", "/topic");
        config.setApplicationDestinationPrefixes("/app");
        config.setUserDestinationPrefix("/user");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/pv").setAllowedOrigins("*");
    }

    @Bean
    public Executor taskExecutor() {
        return new SimpleAsyncTaskExecutor();
    }   

    @Bean 
    public MultipartResolver multipartResolver(){
        return new CommonsMultipartResolver();
    }
}

How can I write a method called for each subscription with path and stompId as parameters ? Thanks

Tobia
  • 9,165
  • 28
  • 114
  • 219

1 Answers1

0

The StompSubProtocolHandler raises appropriate ApplicationEvents when it is necessary:

if (this.eventPublisher != null) {
    Principal user = getUser(session);
    if (isConnect) {
        publishEvent(this.eventPublisher, new SessionConnectEvent(this, message, user));
    }
    else if (StompCommand.SUBSCRIBE.equals(command)) {
        publishEvent(this.eventPublisher, new SessionSubscribeEvent(this, message, user));
    }
    else if (StompCommand.UNSUBSCRIBE.equals(command)) {
        publishEvent(this.eventPublisher, new SessionUnsubscribeEvent(this, message, user));
    }
}

All the necessary information is present in the message. See StompHeaderAccessor API how to obtain the required STOMP information from the message headers on the matter.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118