I make the web-application using Spring MVC and there is a posibility of users to send messages to each other. How can I realize such feature: when the user is on his messages page and he gets the message from someone else, this message adds to his messages list without refreshing the page. Some kind of push notifications, but I can't come up with the right idea, how to realize it.
there's two pieces to consider in this; the 'messaging' framework, and the client-side notification.
typically, the 'messaging' framework would be designed/constructed to be independant of the view layer (Spring MVC piece) and might consist of either a reliable messaging platform (JMS, AMQP, etc.) or some service that allows events to be pushed into the framework. this allows for users to be 'connected' to a JVM instance independant of each other (say a clustered Tomcat environment or some such).
a simpler - old school solution to this was to use a shared database and write/read messages to a shared table with a user identifier; something like from=userA,to=userB,message=... the you could use a polling mechanism to retrieve the messages.
on the client-side, there are a number of patterns including long polling, ajax, websockets etc. that are intended to solve this design question. to marry into the polling solution, an AJAX timed poller (coupled with event) would allow you to continually update a section of your page by requesting from a service "do i (userB) have any new messages?"
the polling solution is "old school" and there are many more options than this. have a dig on topics such as websockets that were developed with this exact challenge in mind. (and have a look at Tomcat8's websocket support too)
Related
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 have a requirement where a Groovy Application is supposed to send event notifications to another Java Web Application Which will than display that data on
web interface.
I don't want to use Queues like ActiveMQ or RabbitMQ because this will introduce an extra layer and will be used if no other solution exists.
An idea have been shared with me that I should expose a web-service from my Java application, which will be consumed by the first application, and the data
sent to the web-service will be then received in second application and somehow displayed on it's web interface.
I am not sure how this will work i.e how the data which is received in web-service of second application will be displayed on its web interface.
Kindly help me to figure out the right solution for this task.
Your problem actually is "how to send notifications from server to browser/mobile client issued by another application".
If you have very strict requirements for latency, then I would suggest to use https://github.com/OpenHFT/Chronicle-Queue
It was created by HFT guys to process 6 millions of messages per second in a single thread.
To display events on user's screen please consider using mechanisms like WebSockets, Server Sent Events, Push Notifications, Long polling, whatsoever depending on your requirements ( like browser support ).
Actually in most cases it doesn't matter what transport are you using. Unless you have super strict non-functional requirements like sub microsecond latency you're free to choose any mechanism, e.g. HTTP, JMS.
Try not to over engineer and design your software based on your actual requirements - not on stackoverflow answers.
Cheers!
I would suggest you create an XML representation of the data you wish to transfer to the java web app. On the java web app if using simple servlets, create a new servlet to which you can post this xml. The servlet could then persist this to a database. This can then be retrieved when a user logs in to the web app at some point.
Let me know if you need any more help. I could only answer only so much based on the question. Some more light on the framework the java web app is using and the data you wish to transfer, might make it easier to add more info.
I'm not really sure how to describe the design issue I'm having so the title is very vague and possibly just totally wrong.
Basically, I have a web application which uses a number of different payment gateways, depending upon which one the user prefers.
Obviously the communication between the application and the gateway endpoint is going to be different for each. I need the way for my application to react to the response of the gateway by the means of a javascript alert (for now). The gateways might have different return url's back to the application, and it needs to work between browser sessions.
Any ideas or pointers to technology that will help with this?
If it helps the technology stack im using: Java, Spring, Struts
Thanks,
I would recommend a dedicated messaging layer with Redis, Socket.io or Rabbit.mq. I had the same issue with a medical app. If you want to stick to Java i would recommend an Observer pattern to pass event messages between classes but you still need a way to distribute notifications to the presentation layer handlers (Javascript) and thats were I recommend a socket server of sorts
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)
I have a web service, that takes an input xml message, transforms it, and then forwards it to another web service.
The application is deployed to two web logic app servers for performance, and resilience reasons.
I would like a single website monitoring page that allows two things
ability to stop/ start forwarding of messages
ability to monitor throughput of number of messages in the last hour etc. Number of different senders into the webservice etc.
I was wondering what the best way to implement this was.
My current idea is to have an in memory database (eg Debry or HSQL) replicating data to share the information between the two (or more) instances of my application that are running in different instances of the app server. I imagine I would have to setup some sort of master/ slave configuration.
I would love a link to an article that discusses how to solve this problem.
(Note, this is a simple spring application using spring MVC)
thanks,
David.
This sounds like a good match for Java Management Extensions (JMX)
JMX allows you to expose certain operations (eg: start/stop forwarding messages)
JMX allows you to monitor certain performance indicators (eg: moving average of messages processed)
Spring has good support for exposing beans as JMX MBeans. See here for more information.
Then you could use an open-source web-based JMX console, such as jManage
Hope this helps.
Sounds like you are looking for a Message Queue, some MDBs and a configurable design would let you do all these. Spring has support for JMS Queues if I'm not wrong
I think you are looking for a message queue. If you need additional monitoring, using a web service as the end point may not suffice - with regards to stop/start or forwarding of messages; monitoring http requests to web service is more cumbersome than tracking messages to a queue (even though you can do it).
If you are exposing this service to third party, then the web service will sit on top of the message queue and delegate to to it.
In my experience, RabbitMQ is a fine messaging queue service with a relatively simple learning curve.