Connect with us

Hi, what are you looking for?

Computer

Integrate JMS & Web Sockets In Java EE7 With CDI events

The main objective of writing this blog is to clarify integration issue between Java EE technologies and web socket API 1.0. And it is also necessary for java programmers to connect with the bugs submitted in CDI specifications, JMS and web sockets. The presence of a java programmer is highly beneficial during specification definition process. Every time when you think about web development project, web socket is kept on the top. Just think you wanted to integrate web socket with whatever is available in your hands. If you are familiar with Java EE7, you must be sure be sure about its rich functionalities like JMS 2.0 that helps in writing simple and effective code lines in no time.

java

You must be shocked how I am successful in sending asynchronous messages to all website sessions. The answer is quite simple, it is CDI. It helps you in establishing communication between distinct parts of application. Let us discuss java programming and how some web socket application will send and receive messages through JMS.

  • Generating web socket server end point

First of all, create a web socket server end point that will receive the message from other end. For this purpose, you need to use three key methods with the web socket, these are – onOpen, onClose, onMessage key methods.

  • Create Session Bean for sending JMS messages

For this purpose, you have to simply integrate JMS and web socket so that messages can be exchanged between the two. Create a session bean that will send messages to JMS queue and create JMS context to inject JMS resources inside. For more understanding, we will advise you to check practical implementation of the session bean in java programming. Once you are completed with session bean, now attach session bean and web socket together for exchanging messages.

  • Redirecting web socket message to JMS destination

We have already attached session bean and web socket together, now call sendMessage method inside onMessage key method. You are advised to opt for constructor injection for avoiding bugs and errors. After this step, one way communication has been established. You can send web socket message to JMS destination. Let us do the reverse function now. Now we will pull out some messages through JMS destination.

  • How to listen a JMS destination through MessageDriven Bean

In Java programming, MessageDrive Bean is not just limited to JMS application only; it can be used for other purposes also. The basic structure for MessageDrive Bean is defined below –

  @Named

  @MessageDriven(mappedName = “jms/myQueue”)

  public class WebSocketMDB implements MessageListener {

  @Override

  public void onMessage(Message msg) { … }

  }

  • Use CDI events with JMS Message Payload

With CDI events, it is possible to connect with observer’s object through which message exchange process can be continued. Once you have fired CDI events, now you must know how to listen these CDI events from server end point. By following all these steps, you can establish two-way communication between JMS and web socket successfully. In case of any confusion, you can check coding section for full implementation. Thanks to the tutorial as we are able to scale up server pushed data.

Written By

Evan, Who has worked in CRM Development Application. He has very experience in a technical architect in Aegis Soft Tech. Also, wide range of skills across the Microservice Development, SQL Server, text analytics, AngularJS task. With a prove track the record of working on and leading the enterprise level projects.

2 Comments

2 Comments

  1. Pingback: Integrate JMS & Web Sockets In Java EE7 Wit...

  2. Subham

    February 17, 2014 at 6:19 pm

    Java messaging service is difficult to understand you posted a very informative article cheers !!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

Tech

Java has significant advantages over other languages which is why many businesses still prefer using it for development. Read the complete post to know...

Tech

Cloud seems to be everywhere — individuals are raving about it just as much as businesses. And none of that popularity the cloud enjoys...

Tech

Having celebrated its 24th anniversary in 2019, Java has witnessed constant development in its programming performance for decades. It is one of the most common programming languages...

Web

Those even vaguely familiar with Java know that it includes interface and abstract class. The interface is a template that can be leveraged to...