How to use ExecutorSubscribableChannel

£可爱£侵袭症+ 提交于 2019-12-08 08:19:31

问题


Related with the question autowire simpmessagingtemplate

I am having problem the class ExecutorSubscribableChannel. I want the server to send a asynchronous message to the browser. How can I use properly ExecutorSubscribableChannel ?

Example:

public class GreetingController {


    @Autowired
    private SimpMessagingTemplate template;

    public void setTemplate(SimpMessagingTemplate template) {
        this.template = template;
    }

    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        Thread.sleep(5000); // simulated delay
        this.template.convertAndSend("/topic/greetings", "Hello World");
        return new Greeting("Hello, " + message.getName() + "!");
    }
}

but the "hello world" text that I am sending in the line

this.template.convertAndSend("/topic/greetings", "Hello World");

is not being received by the browser. Everything else works fine.

The beans configuration is:

<bean id="executorSC" class="org.springframework.messaging.support.ExecutorSubscribableChannel"/>

<bean id="template" class="org.springframework.messaging.simp.SimpMessagingTemplate">
    <constructor-arg index="0" ref="executorSC"/>
</bean>

Thanks in advance.


回答1:


This question was written due a bug in Intellij IDEA. The response is in Could not autowire. No beans of SimpMessagingTemplate type found

A ticket has been create in JetBrains to solve this problem.




回答2:


try using this configuration

<websocket:message-broker
    application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/ws">
        <websocket:sockjs />
    </websocket:stomp-endpoint>
    <websocket:simple-broker prefix="/topic/greetings" />
</websocket:message-broker>

insted of

<bean id="executorSC" class="org.springframework.messaging.support.ExecutorSubscribableChannel"/>



来源:https://stackoverflow.com/questions/23026408/how-to-use-executorsubscribablechannel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!