如何向多个用户发送消息并ping用户stomp

时间:2014-12-15 17:20:38

标签: java spring websocket message-queue stomp

如何通过弹簧项目中的stomp来ping活动用户? 我已经搜索了2天但是这段代码无效 客户端脚本:

var socket = new SockJS('/connect');   
stompClient = Stomp.over(socket);
stompClient.subscribe('/topic/active', function(activeMembers) {
        console.log(activeMembers);
        showActive(activeMembers);
    });

这是弹簧配置:

 <websocket:message-broker application-destination-prefix="/chat">
    <websocket:stomp-endpoint path="/connect, /activeUsers">
        <websocket:handshake-interceptors>
            <bean class="uz.mirworldstyle.sensation.component.MessagingHandshakeInterceptor"/>
        </websocket:handshake-interceptors>
        <websocket:sockjs/>
    </websocket:stomp-endpoint>
    <websocket:simple-broker prefix="/topic, /queue"/>
</websocket:message-broker>

这是java类:

@Service
public class ActiveUserPinger {

@Autowired
private MessagingController messagingController;

@Autowired
MessageSendingOperations<String> stringMessageSendingOperations;

@Autowired
private ActiveUserService activeUserService;

@Autowired
private SimpMessagingTemplate template;


@Scheduled(fixedDelay = 2000)
public void pingUsers() {
    Set<Integer> activeUsers = activeUserService.getActiveUsers();

    template.convertAndSend("/topic/active", activeUsers);
    stringMessageSendingOperations.convertAndSend("/topic/active", activeUsers);
}
}

0 个答案:

没有答案