Giter Club home page Giter Club logo

jms-websocket's Introduction

Java EE 7 Example for JMS and WebSockets integration

This application demonstrates a full-duplex scenario using WebSockets and JMS, with a fully functional server-side asynchronous push, using CDI events and EJB.

Details and step-by-step were blogged here: https://blogs.oracle.com/brunoborges/entry/integrating_websockets_and_jms_with

How does it work?

On the client side, a websocket session is opened with java script:

websocketSession = new WebSocket('ws://' + ...);

and messages are sent by:

websocketSession.send(msg);

The callback handler is implemented as f_onmessage(evt) which adds a message to the <div> element.

On the server side, there is a websocket server. When a message arrives from a websocket client, it uses the injected QueueSenderSessionBean service to send a message to a JMS queue.

A MessageDrivenBean picks up that message and fires a CDI event.

The websocket server listens for CDI events and picks it up and send a message to all websocket clients.

There is a REST service, too. The Endpoint class exposes a GET method which is available under: http://127.0.0.1:8080/jms-websocket-1.0-SNAPSHOT/rest/example/ The REST service uses the injected QueueSenderSessionBean service to send a message to a JMS queue.

A MessageDrivenBean picks up that message and fires a CDI event.

The websocket server listens for CDI events and picks it up and send a message to all websocket clients.

How to test it?

  1. mvn clean install

  2. cp target/jms-websocket-1.0-SNAPSHOT.war $WILDFLY_8.1_HOME/standalone/deployments/

  3. $WILDFLY_8.1_HOME/bin/standalone.sh -c standalone-full.xml

  4. Open two browser sessions (tabs) and navigate to http://127.0.0.1:8080/jms-websocket-1.0-SNAPSHOT/

  5. Click on Open Session on both tabs and start sending messages.

  6. Open another browser session and navigate to http://127.0.0.1:8080/jms-websocket-1.0-SNAPSHOT/rest/example/myMessage

  7. "myMessage" should be displayed on the other two tabs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.