How configure the Spring Sockjs Java Client message converters

我怕爱的太早我们不能终老 提交于 2019-12-06 12:19:20

try to create a Bean like

public class SimpleBean{
private String from;
private String text; 
public String getFrom(){return from;}
public String getText(){return text:}
//other methods like setters here... 
}

then set the messageConverter in this way

            MappingJackson2MessageConverter m = new MappingJackson2MessageConverter();
            stompClient.setMessageConverter(m);

I have not seen any invocation of the "subscribe" method for your client in the method "afterConnected(StompSession session, StompHeaders connectedHeaders)"

    session.subscribe(subscribeMethod, new StompFrameHandler() {
//.. overriding for public Type getPayloadType(StompHeaders headers) {} and
// public void handleFrame(StompHeaders headers, Object payload) {} here
});

Than call for the "send" method, using an instance for the SimpleBean defined just before:

SimpleBean sb=new SimpleBean();
sb.setFrom("cliente1");
sb.setText("KIKO");
session.send("/app/chatchannel", sb);

This should help.

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