We're starting work on a monitoring application that will be providing status for several pieces of hardware. The data will be updated on an Oracle DB by a backend process, this application will have to be developed in Java and deployed on a WebLogic 12c application server stuck behind an Apache HTTPD server.
Since the monitoring will be real-time, we'll be needing almost instant refresh of the data that was added on the database. To achieve this, I've been doing some tests with the following frameworks:
Hibernate as ORM.
Spring 3.0.5.
JSF 2.2 and PrimeFaces 3.5 with PrimeFaces Push (Uses Atmosphere).
My tests were successful and I was able to get something working quite quickly. However, I've noticed that Atmosphere has some potential that is being contained by the PF implementation, also, I don't know if this is the most lightweight solution.
Because of this, I wanted to ask you if you guys had any other approaches for this solution, i.e:
Spring MVC + Atmosphere.
Other MVC + Other Comet/WebSocket framework.
Most of the data shown will be for charts, tables and maps. The biggest limitation will be that everything must be Java compatible, since the application server won't be changed.
To summarize, my question is:
Which alternative options do you suggest for this project based on the requirements and limitations I established?
Let me know if you need additional information.
Spring 4 has good Websockets support, have a look here at the documentation. It makes possible to create a websockets endpoint, and use it in a publish-subscribe model based on the STOMP protocol.
This protocol is a messaging protocol that allows to subscribe to a topic and receive notifications, publish to a topic to all subscribed listeners or send a server push message to a single client.
Currently Websockets might not work for all users due to browser limitations, proxies that are not configured to forward the upgrade headers needed to upgrade from HTTP to Websockets, or network elements that timeout long-lived connections.
Spring 4 provides good support for this via SockJS, which has transparent fallback capabilities (to ajax, iframe) if a Websocket connection cannot be established.
All these things are needed to use Websockets in this day and age, and Spring 4 provides a complete out-of-the-box solution.
Have a look at this blog post to see how lightweight this solution is, specially if used together with Spring Boot.
If it's a frontend intensive application you might to couple Spring 4 with AngularJs, for frontend widget development. But Primefaces is a great solution, if the widgets they provide suit your needs it would spare a lot of work.
Related
I have a design question: I use DB + Hibernate + SpringBoot as back end in a server and use Swing clients on desktops.
I am considering for a new project the following architecture:
Back end (maybe in separate servers):
SQL DB
Spring Boot + Hibernate Java App
Front end(s):
Swing Java App
later: mobile App; Browser
I have searched a bit, but still have some doubts and feel I am missing something. I initially considered using React for front end. But this is going to take too long for me and I have lots of Swing components that I already optimized (and this my applications tend to use lots of grids with edits "in place")
I searched for Spring + Swing, but what I found was about running everything on the same JVM. I would think that separating them would allow me to (later) build a Mobile or Web front end using the same back end.
To sum it up:
create back end services with spring boot + hibernate on top of SQL db
create Swing front end that consumes those services
(later stage) mobile app to consume these same services
Questions:
Is this a good approach ? Am I seeing this the wrong way
How to "share" the POJOs between the back end and the front end? (thinking about placing the models on a separate lib); I don't mean how to transport them, I mean how to reuse them on both projects.
This is possible.
I would create the backend application with Spring Boot and access a datastore with Spring DATA. I would make services available via REST.
To access REST from your Swing client you must use a REST client of some sort. I would recommend Spring RestTemplate but there are many alternatives.
Synchronous client to perform HTTP requests, exposing a simple,
template method API over underlying HTTP client libraries such as the
JDK HttpURLConnection, Apache HttpComponents, and others.
Since you want mobile support some time in the future you could consider creating a webclient instead and making it cross platform (browser only).
To answer your two questions:
Regarding backend you will be perfectly fine as Spring Boot is a good option. As for the client I personally would not choose Swing today since it is very old and rather go for JavaFX 2 or a web client if that is an option. If you are the only developer and since you are proficient it might be a good solution for you.
You can share the POJOs from you Server for your Client as an api that you include as dependency. However it is usually not recommended to share POJOs but rather generate it on the client side or just type them. In your case if it is a small project it probably is ok. Do what is most easy for you.
I would recommend start using Maven as a build tool if you do not already.
Good luck.
Your request is perfectly valid, as you are a Swing developer and your approach is absolutely fine.
So let's draw the general picture: you're building a backend/frontend product/software.
Backend
Your backend will be a Spring application that will run on a server, let's say http://localhost:8080, serving requests to clients.
You'd probably want to create a #RestController on http://localhost:8080/api/... to expose your functions to your Swing client.
Swing client
Your client will be a Swing application running on your desktop.
To connect your client to the Spring application, you now need to implement a service in your Swing application that will call your Spring web server and fetch the resources from there.
To achieve this goal, may options exist:
Why not plain Java ? Use this tutorial to call your Spring services.
Http components from Apache are quite common.
Spring your app ! Spring API includes RestTemplate that you can use in your Swing app to call Spring backend and fetch resources for your desktop app.
As you can see, this is EXACTLY the same thing as with a website in React:
your web page is the JFrame
your JSX components in React would be your JPanels and components
you'd connect action listeners on components (JComboBox, JButton) to a service calling your Spring backend.
you'd then use the resources fetched from your Spring server to update your application state.
rince and repeat
So, be confident, your approach is correct. You'll find people ranting at you having chosen an obsolete techno but really, who cares?
(May I add, totally a pun, you've been smarter than the JavaFX guys which are now facing the segregation of javafx libraries from the core Java ;-))
And as always... happy coding !
I have to implement a notification system within a Java Spring app with angular for a front end. I was advised on using Spring XD as the message broker. However after looking at it, I am unsure if this would be a good strategy. It might be possible but will look like a hack.
EDIT: I have a simple use-case. On the web app if user A does an action X, then I need to notify user B about action X using notifications in the web app (if the user B is currently logged in), through GCM and through SMS.
AFAIK, Spring XD is a framework which allows us to communicate with several different Message Broker (among other things that it does). So, Spring XD itself cannot act as a MB Server. As a MB server, you have several options like ActiveMQ, RabbitMQ, Kafka....
If you are planning to build a message oriented system from ground up, then Spring XD could be a good choice. If you are just looking for adding a new feature in existing application, you can achieve communication to any of the above MQ servers using Spring Integration (recommend you check Spring Integration Java DSL). This way you will be easily integrate it with existing application.
I am currently writing a forum web-application using Spring MVC. I'm just a beginner at Spring and have only been working with it for about 1 week now.
I need to implement push notifications. Here is the scenario: User A logs in and creates a post. User B comments on User A's post while User A is still logged in. User A receives a notification that some user has commented on his post, without his browser refreshing the page.
I need help with sending the notification to User A that User B has commented on his post asynchronously. I have done some research, and found that there is a package called CometD that I can use, but I cannot find any simple tutorials for me to understand.
Can anyone suggest any other packages/way to solve my problem? Or if you have any simple CometD tutorials, that would be great as well.
I am the CometD project lead.
CometD ships with a demo war file that has a built-in chat application that you can use as a basis to understand how CometD works, see https://docs.cometd.org/current/reference/#_installation.
The CometD full reference documentation is here: https://docs.cometd.org.
From experience, I don't recommend using Servlet 3.0 async features to implement a chat, because that will rule out usage of WebSocket.
It's better you rely on frameworks such as CometD that can start with WebSocket (as it is more efficient) and then fallback automatically and transparently to HTTP if WebSocket does not work.
On a similar note, I don't recommend a WebSocket only approach because WebSocket does not work in certain scenarios (for example, mobile networks often do not allow WebSocket traffic), and it's a too low-level protocol so you will have to build your own protocol on top of WebSocket (which is a lot of work and not easy to get right).
CometD provides you with an easy to extend protocol and automatic transport fallback, and has a ton of features (e.g. authorization & authentication and clustering just to mention two).
Have a look at the spring MVC chat sample app for spring MVC 3.2, there is also a spring blog post about it.
In one of our recent projects, we have decided to use a message based solution to integrate an existing .Net app to a new JAVA based application. There is a requirement to not use a Application Server. So I am trying to look into some alternative options. Currently we are planning to use ActiveMQ as the JMS provider. Also the Java application needs to interact with an backend database. So, when trying to figure out options, I found that the Spring framework would be quite helpful. It appears that Spring may need some additional components (e.g, Atomikos) to provide transaction support for JMS & JDBC operations.
I am trying to limit the user of additional components as much as possible.
So, Is this the right approach to use ActiveMQ with Spring. If so, can I just use the built-in transaction module available in Spring to support transactions?
Any advice would be very helpful?
Leo
Use WebSphere MQ .NET interface (.NET native or XMS .NET) for sending/receiving messages from your .NET application. At the Java app end use MQ JMS interface. MQ JMS interface supports two phase commit, so you can synchronize your message gets and database updates.
Keep the integration through MQ and WS. More tight coupling may lead to problems and complexity.
I'd go with a messagequeue that has good .NET and Java clients - e.g. RabbitMQ That builds on AMQP. As well as serialization technology that has good cross-language capabilities (Thrift, Protocol-buffers etc.)
I've seen a bunch of screencasts demonstrating the integration between blazeds and flex, also some lcds tutorials, model driven or not.
I've seen that some of them the presenter opens 2 browsers and once you change one value in a grid, it propagates to all other grids that presents the data.
I am wondering how the heck this is done, and how to reproduce.
Does this feature depends of the Edge / LCDS solution? I don't think so, but I've never seen some code explaining about it.
I feel it may or may not rely on JMS / MQ / messaging protocols or if this is some sort of 2 way sync and propagation of collection between instances of the same service result.
Thanks for any inputs.
Cheers,
Ernani
You can implement this feature both with BlazeDS and LiveCycle Data Services. BlazeDS provides remote and messaging features (the messaging features is the one allowing you to synchronize the data between the clients), LCDS extends BlazeDS adding new features like data management (productivity improvements), PDF generation, EDGE server for dealing with DMZ zones), MDA development, portal integration etc. It also adds some advanced messaging features like message conflation, throttling, reliability.
BlazeDS is free and open source and in my opinion a robust solution, you can use it if you want to synchronize the data between clients. LCDS adds a lot of things, but the LCDS customers should have a large budget.
How does it work? There is no JMS behind for this feature (however BlazeDS can integrate with a JMS provider so you can have one client in broswser and the second one running a SWING application). Instead there are some message queues on the server and a publisher - subscriber graph. In order to push the data from the clients to the server there are several choices, the more advanced are available only on LCDS: HTTP polling, HTTP long polling, HTTP streaming, RTMP sockets (LCDS only). All of them are described in details on Damon blog.
If you want to see some code go and download BlazeDS and take a look on the samples, there are several ones showing the messaging features. Also there a tomcat server is bundled in the download, and the samples are already deployed in it.
To do this you need to keep an open socket connection between the client and the server so that the server can push data back to the client.
I believe that the RTMP protocol was used for this two-way communication.
I understand that this is the primary reason to use LiveCycle Data Services over BlazeDS. WebORB also has push functionality, as does GraniteDS. I've also seen demos where this is done with ColdFusion.
If none of those options are available to you, you're stuck doing some kind of polling to the remote server.
Unfortunately, I do not have specific code samples to share.
A simple sample showing how to do this using WebORB can be found here:
http://www.kensodev.com/2009/11/01/synchronize-client-application-using-flexweborb-net/
That sample is based on WebORB 3 for .NET; WebORB 4 is now available, for both .NET and Java.
Point being: This is brain-dead simple using WebORB, which is FREE (although a paid Enterprise version is also available). God forbid that anyone should shell out $30K for LCDS just to get this feature.
--- Jim Plamondon, Midnight Coders (makers of WebORB)