Monday, October 13, 2014

JavaFX2 Message Broker Client For The Rest Of Us

Developers of systems for Enterprise Integration often need to interact with a message broker in order to view messages or send messages to queues or topics. The problem is, a client application which does that is not always readily available.

Now there is one!

You can now use the MQConsole client application (at least for Apache ActiveMQ and HornetQ). MQConsole is an open source application that I started to develop using a maven multi-module project. Each broker support in developed as a maven module and shares the same user interface with the others. The source code is available on Github (here) and the binary distributions for Windows and Mac are available on Bintray (here).

main window - broker destinations
The main window shows a table with information about the queues and topics found in the message broker. There are a number of actions available if you right-click on any queue or topic:
  • See the list of messages in a queue or topic
  • View the details of a specific message
  • Send a new message to a queue or topic
  • Subscribe to a queue or topic and display messages as they arrive there.

send a new message window
When sending a new message, you can opt for a request/response scheme by ticking the "Has Response" box. In this case, the application will wait for a response and displays the reply message in the "Response" tab.
Window displaying a received message
When you subscribe to a channel or topic in the main window, a window displaying one message pops up every time a new message arrives.
This window can also be opened to view the details of a message in a message list.

The message details displayed are the message headers and its payload as long as its non binary.

Please download from Bintray and see the Github site to create an issue with your improvement suggestions

Requires Java 8 update 20 or a newer version.

Monday, October 6, 2014

JavaFX2 Websocket Client Deployed by Webstart JNLP

This post builds on the previous Websockets with Spring Framework 3.x and answers 2 questions:

  1. How to use webstart-maven-plugin to pack a JavaFX 2 client in a web application and launch it using Java Web Start (JNLP)
  2. How to use Tyrus, a java websocket client implementation, for client server websocket communication
The source code referenced here is part of a fully functioning application which can be downloaded and tested from the websocket-test repository at Github. Please read the README file there for pre-requisites and instructions on building and testing.

Project structure:

Maven project called websocket-test (packaging: pom) with two modules:

  1. websocket-client - JavaFX 2 application (packaging: jar) 
  2. websocket-server - Spring framework web application  (packaging: war)

Project packaging

The websocket-server module is packed with the depicted structure. The webstart folder contains the jar file generated by the websocket-client module and it's transient dependency jars. It also contains the websocket-client.jnlp descriptor file

I - Using webstart-maven-plugin to pack a JavaFX 2 client in a web application and launch it using Java Web Start (JNLP)

On the websocket-server module, configure the webstart-maven-plugin as follows:

Notice the build timestamp passed to the JNLP file. this will allow java web start to detect wether a cached application needs to be refreshed.
The details pertaining to the user certificate in the <sign> section are defined in the maven settings.xml file, so they remain private.

You must also provide a velocity template for the JNLP file, like the following:

This template contains variables. Some of them will be substituted at build time (ex: ${buildTS}) and some will be substituted by the JnlpDownloadServlet at download time (Ex: $$context)

Notice the parameter definition on line 28 (<fx:param name="server-url" value="$$context"/>). This will be passed to the JavaFX2 application and will tell it where to connect the client websocket.

II - Using Tyrus for client server websocket communication

Tyrus is the websocket reference implementation in java therefore it made sense to build this test project using Tyrus, although any other implementation could be used.

The application is going to establish a websocket connection to the server and the address of the server is calculated based on the value of the server-url parameter in the JNLP file:

Starting the Tyrus client manager will create a separate process with several execution threads to control communication between the client and the server. We need to tell the application that the security permissions bestowed by the java web start configuration are needed to launch the Tyrus client, otherwise an "access denied" exception will be thrown. We do this by starting the Tyrus client in a privileged block:

Please download the source code for all the details (git clone and leave a comment here or raise an issue at Github if you have any thoughts or suggestions you'd like to share.