2016-04-06 9 views
4

Merhaba mesajları göndermiyor ama any.I aşağıdaki Stomp ile bahar çizme kullanıyorum almıyor benim sınıfları SimpMessagingTemplate Ben Endpoints Stomp mesaj göndermek için çalışıyorum bütün yay çizme

@Controller 
public class GreetingController { 

    @MessageMapping("/hello") 
    @SendTo("/topic/greetings") 
    public Greeting greeting(HelloMessage message) throws Exception { 
    System.out.println(message.getName()); 
    Thread.sleep(13000); // simulated delay 
    return new Greeting("Hello, " + message.getName() + "!"); 
    } 

} 

@Controller             
public class Testcont { 

    @Autowired 
    private SimpMessagingTemplate messageSender; 

    @RequestMapping(value="/Users/get",method=RequestMethod.POST) 
    @ResponseBody 
    public String getUser(@RequestParam(value = "userId") String userId, @RequestParam(value = "password") String password, @RequestParam(value="port") String port, HttpServletRequest request) { 
    HelloMessage mess=new HelloMessage(); 
    mess.setName(userId); 
    messageSender.convertAndSend("/app/hello",mess); 
    return "Success"; 

} 

ve WebSocket'e benim Yapılandırma vardır

@Configuration 
@EnableWebSocketMessageBroker 
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { 

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

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

} 

Konsollarda hata göremiyorum. Yukarıdaki kod web tarayıcıları ile harika çalışıyor.

+0

Bu Zahid'i nasıl başardınız? m aynı sorun üzerinde sıkışmış ve ben –

cevap

4

SimpMessagingTemplate fasulye tam Broker parçası (AbstractMessageBrokerConfiguration) içindir:

@Bean 
public SimpMessagingTemplate brokerMessagingTemplate() { 
    SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel()); 
    String prefix = getBrokerRegistry().getUserDestinationPrefix(); 
    if (prefix != null) { 
     template.setUserDestinationPrefix(prefix); 
    } 

değil komisyoncu hedefe (sizin durumunuzda /app/), böyle bir mesaj sadece AbstractBrokerMessageHandler.checkDestinationPrefix(destination) tarafından göz ardı edilir göndermek beri.

aynı @MessageMapping tarafından iç mesajı işlemek isterseniz, size SimpAnnotationMethodMessageHandler tarafından sağlanır doğrudan clientInboundChannel, kullanmalısınız: Sana için kendi SimpMessagingTemplate örneğini oluşturabilir tahmin

@Bean 
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() { 
    SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler(); 
    handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes()); 

clientInboundChannel, brokerMessagingTemplate fasulyesine benzer. Ve iyi olacaksın.

+0

cevabını anlayamadım Teşekkürler Ben şimdi nerede hata yapıyorum biliyorum. –

+0

Artem Cevabı anlamadım, bana rehberlik edebilir misin? –

+0

Rehber olduğunuzdan emin değilsiniz, ancak Referans Kılavuzundan başlamak gerçekten daha iyi olacaktır: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html . Her şey dinlenme, ayrı SO iş parçacığında ele alınmalıdır. –

İlgili konular