【问题标题】:Websocket in AWS ElasticBeanstalk Tomcat & Spring not workingAWS ElasticBeanstalk Tomcat 和 Spring 中的 Websocket 不工作
【发布时间】:2018-03-20 07:41:53
【问题描述】:

我在 AWS EB 中使用 Tomcat。我使用 Spring Boot 和技术堆栈 Spring 4 和 Java 8 开发了一个应用程序。我的应用程序使用 Spring WebSocket 向用户发送通知。以下是javascript条目

<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js" ></script>

// Create and init the SockJS object
var socket = new SockJS('/partnervestcrm/message');
var stompClient = Stomp.over(socket);
// Subscribe the '/notify' channell
stompClient.connect({}, function(frame) {
  stompClient.subscribe('/user/queue/notify', function(notification) {
    // Call the notify function when receive a notification
    //notify(JSON.parse(notification.body).message);
    notify(JSON.parse(notification.body));
  });


}, function(error) {
    alert("STOMP error " + error);
});

当部署到 AWS EB 时,这在我的本地运行良好,但出现以下错误

WebSocket connection to 'ws://xxxxx/notification/298/plu4ia32/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
WrappedWebSocket @ VM152:164
e.exports @ websocket.js:6
r @ websocket.js:32
r._connect @ main.js:219
r._receiveInfo @ main.js:193
n @ emitter.js:30
r.emit @ emitter.js:50
(anonymous) @ info-receiver.js:67
n @ emitter.js:30
r.emit @ emitter.js:50
(anonymous) @ info-ajax.js:37
n @ emitter.js:30
r.emit @ emitter.js:50
xhr.onreadystatechange @ abstract-xhr.js:124

请告诉我如何解决这个问题?

【问题讨论】:

    标签: amazon-web-services tomcat spring-websocket amazon-elastic-beanstalk


    【解决方案1】:

    为安全组添加入站规则解决了这个问题。请在 ec2 仪表板 > 网络和安全(在左窗格中)> 安全组 > 入站中添加规则

    【讨论】:

      猜你喜欢
      • 2015-09-03
      • 2014-07-06
      • 2018-03-28
      • 1970-01-01
      • 2017-02-23
      • 2023-03-12
      • 1970-01-01
      • 2018-07-25
      • 2016-09-20
      相关资源
      最近更新 更多