如何使用executorsubscribablechannel
-
21-12-2019 - |
题
与问题有关 autowire simpmessagingtemplate
我正在遇到class executorsubscribablechannel。我希望服务器将异步消息发送到浏览器。如何使用正确的executorubscribablechannel ?
示例:
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() + "!");
}
}
.
但是“Hello World”的文字,我在线发送
this.template.convertAndSend("/topic/greetings", "Hello World");
.
浏览器未接收。其他一切都适用。
bean配置是:
<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>
.
提前感谢。
解决方案
这个问题是在Intellij Idea中的错误编写的。响应是无法自动。没有发现simpmessagingtemplate类型
a 票据已在JetBrains中创建以解决此问题。
其他提示
尝试使用此配置
<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>
.
而不是
<bean id="executorSC" class="org.springframework.messaging.support.ExecutorSubscribableChannel"/>
.
不隶属于 StackOverflow