AWS ElasticBeanstalk中的Websocket Tomcat&春天不工作

时间:2017-10-09 07:13:29

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

我在AWS EB中使用Tomcat。我使用Spring引导开发了一个带有技术栈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

你能告诉我如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

添加安全组的入站规则解决了这个问题。请在ec2仪表板中添加规则&gt;网络&amp;安全(在左侧窗格中)&gt;安全组&gt;入站

enter image description here