有人可以让我知道如何从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客户端来连接到此套接字和主题。提前致谢