簡體   English   中英

通過WebSocket在WebPage上顯示JMS消息的Spring-boot應用程序

[英]Spring-boot app displaying JMS messages on WebPage via WebSocket

我在spring-boot中需要一個簡單的Web應用程序,它可以偵聽JMS隊列上的消息,並且到達時應通過WebSocket出現在網頁上。

我搜索了一些例子,發現了幾個個體。 我自己測試過的WebSocket或JMS,但沒有成功將它們連接在一起。

我已經搜索了一個示例,但沒有找到任何示例,我認為這應該很容易,因為這是一個非常基本的要求。

您是否知道任何可以通過WebSocket共享的JMS和HTML顯示示例,或者可以為我提供一些提示或幫助來解決該示例?

Spring Integration可以提供幫助。

您可以編寫<int-jms:message-driven-channel-adapter>來從JMS隊列中讀取消息,並將其轉發到<int-websocket:outbound-channel-adapter> 最后一個只是向連接的WebSocket會話發送消息的地方。

有關此問題,請參見這些Spring Integration示例:

https://github.com/spring-projects/spring-integration-samples/tree/master/basic/jms

https://github.com/spring-projects/spring-integration-samples/tree/master/basic/web-sockets

UPDATE

要將消息發送到所有訂閱的WebSocket會話,您應該執行以下操作:

<int:splitter input-channel="enricheMessage" output-channel="sendMessage" apply-sequence="false">
    <int-groovy:script>
        @serverWebSocketContainer.sessions.keySet().collect {
            org.springframework.integration.support.MessageBuilder.withPayload(payload)
                    .copyHeaders(headers)
                    .setHeader('simpSessionId', it)
                    .build()
        }
    </int-groovy:script>
</int:splitter>

使用此Groovy腳本,我從serverWebSocketContainer (所有那些連接的客戶端)中檢索session ids ,對其進行迭代以構建消息以通過WebSocket發送它們。 最后split ,一一發送到<int-websocket:outbound-channel-adapter>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM