当前位置:  开发笔记 > Android > 正文

Spring Stomp Web Sockets Client for Android

如何解决《SpringStompWebSocketsClientforAndroid》经验,为你挑选了0个好方法。

有人可以让我知道如何从android客户端连接到spring stomp Web套接字。

WebSocketConfig.java

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/pushticket");
        config.setApplicationDestinationPrefixes("/rest");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ticket").withSockJS();
    }

}

PushMessageNotifier.java

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;    

@Service
@EnableAsync
public class PushMessageNotifier {

    private SimpMessagingTemplate simpMessagingTemplate;

    @Autowired
    public PushMessageNotifier(SimpMessagingTemplate simpMessagingTemplate) {
        this.simpMessagingTemplate = simpMessagingTemplate;
    }

    @Async
    public Boolean pushToUI(TicketView ticketView) {
        Boolean result = false;
        if (null != ticketView) {
            this.simpMessagingTemplate.convertAndSend("/pushticket/ticket", ticketView);
            result = true;
        }
        return result;
    }

}

请告诉我如何从android应用程序连接到此套接字?甚至我都不知道我需要使用哪个Android客户端来连接到此套接字和主题。提前致谢

推荐阅读
牛尾巴2010
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有