小编Mni*_*ick的帖子

Websocket:如何将消息推送给目标用户

我正在尝试使用websocket并使用sock.js在spring中实现推送通知.

这些是代码片段:

    public class NotifyController {

        @MessageMapping("/notifications")
        @SendTo("/get/notifications")
        public Greeting greeting(HelloMessage message) throws Exception {
            new Greeting("Hello, " + message.getName() + "!");
        }
    }


    public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
        @Override
        public void configureMessageBroker(MessageBrokerRegistry config) {
            config.enableSimpleBroker("/get/notifications");
            config.setApplicationDestinationPrefixes("/gssocket");
        }

        @Override
        public void registerStompEndpoints(StompEndpointRegistry registry) {
            registry.addEndpoint("/notifications").withSockJS();
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是前面的代码..

    function connect() {
        var notificationSocket = new SockJS('/notifications');
        stompNotificationClient = Stomp.over(notificationSocket);

        stompNotificationClient.connect({}, function(frame) {
            console.log('Connected: ' + frame);
            stompNotificationClient.subscribe('/get/notifications', function(greeting){
                showGreeting(JSON.parse(greeting.body).content);
            });
        });
    }

    function sendNotification() {
        var name = "test" …
Run Code Online (Sandbox Code Playgroud)

java spring websocket

10
推荐指数
1
解决办法
6122
查看次数

在控制器中断言与如果

检查在控制器中传递的值的最佳方法是什么?

是断言还是如果?

如果这是示例网址....

http://example.com/read/1/2

我想检查 1 和 2 是否为数字以及是否为空。就像用户将 url 更改为http://example.com/read/1asdf/2asdfqwer 一样

我们在我们公司使用断言。我只是在想如果它已经处于生产模式并且断言被禁用会发生什么。

有人给我一个洞察力。

java spring spring-mvc

3
推荐指数
1
解决办法
3036
查看次数

标签 统计

java ×2

spring ×2

spring-mvc ×1

websocket ×1