Are there any plugins for broadcasting events in spring boot - java

I would like to broadcast a message across microservices, whenever any database is updated.
Example:
Stock value keeps changing, how do i notify all to use the latest value everytime the stock value is updated.
Can anyone suggest any tools or plugins for the same which could be embedded with spring boot.
An example code would be very helpful

If you need something more complex, then you can find tons of examples with AMQP, Spring JMS, Redis pub-sub in this book.
One easy solution for basic state changes, would be instead spring-cloud-bus.
Spring Cloud Bus links nodes of a distributed system with a
lightweight message broker. This can then be used to broadcast state
changes (e.g. configuration changes) or other management instructions.
The only implementation currently is with an AMQP broker as the
transport, but the same basic feature set (and some more depending on
the transport) is on the roadmap for other transports.
A common use case is the change in the config server that needs to be updated in all the microservices. While normally we would change the value in the config server and then hit the refresh endpoint for each service, the config cloud bus updates them all making the process easier.

Related

JMX Notifications design

We have a number of related Java Spring applications running on our servers. Lets call them App1, App2 & App3. As is standard all these use the common code in our-common-utils.jar
I want these applications(App1, App2 & App3) to broadcast their state to one or more remote listeners. For e.g.
App1: I failed to read file abc.
App2: I am using more than 90% of my heap space etc.
The listener/s of these events will take specific actions such as send emails to support and/or clients based on the notifications received.
The best solution I can think of is to have a NotificationSender JMX enabled(implements NotificationBroadcasterSupport) bean in our-common-utils.jar. This will have a thread consuming from a queue of Notifications and firing off sendNotification() to the listeners for each Notification. This will be done by each of the Apps in our eco system but using common code from common-utils.
Do you see any flaws in this design? Any more efficient ways/frameworks of doing it?
Many Thanks :)
Alternative solution is to use any distributed coordination service zookeeper for example. I used it in my very first micro service project. As I can see you are using spring. Spring cloud provides necessary solutions that you can use in declarative way. I would pay your attention to #FeignClient. It is very simple in use and flexible in spring world.
If I would work on this issue now, I would use spring hystrix based solution. To simplify integration between your java services I would recommend to check service-registration-and-discovery.
Ignore my opinion if spring is not general engine part in your projects (may be you need other vendor solutions, there are a lot of alternatives). I concentrate my attention on spring solutions because spring is not restricted in my projects and I can use anything I wish if it's reasonable.

Can Spring XD be used as a message broker for notifications?

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.

Frameworks for Monitoring Application

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.

Which websocket server implementation can be combined with rabbitmq?

Hi there we are planning on integrating a websocket server implementation as frontend to our RabbitMQ systems. Currently we are running some Java/Groovy/Grails based apps which use the RabbitMQ server.
We would like to have a simple websocket server implementation that handles connections etc and that passes the request to our RabbitMQ layer.
Clients (hardware devices) would connect to a websocket layer that handles the request to RabbitMQ. Some other process takes on the job of handling the request and places back data in the queue if needed so that RabbitMQ is able to pass the data via websockets back to the client.
I am a bit lost in the land of websockets so i am wondering what other people would advise to use.
You can use rabbitmq itself with the webstomp plugin and sock.js for web frontends. You can expose this directly or via something like haproxy.
http://www.rabbitmq.com/blog/2012/05/14/introducing-rabbitmq-web-stomp/
In version 3.x it is now included by default, just enable the plugin.
For Java there are a couple of choices:
Atmosphere
Vert.x
Play 2.0
Netty directly
There are so many ways to skin the cat. Atmosphere will probably get you the furthers if you already using Grails. You will have to write a custom Broadcaster IIRC there is not one for RabbitMQ but you can just copy one of the existing ones.
Also with RabbitMQ or any queue your going to have to decide whether your going to make queues for each for each user (browser using websocket) or your going to aggregate based on some hash and then dispatch internally (ie make a giant map of mailboxes). Akka would be a good choice for mapping to mailboxes.

Managing Shared Property File across Server Instances

I have developed Flex - Java - Spring Web Application that I have deployed into an Amazon EC2 image - all is looking great.
However, I need to auto scale and share User requests between multiple instances of the application that sit on different machines, i.e not within the same Tomcat Container. Amazon manages the load balancing and the application uses AMQ topics to communicate critical application level changes between each of the instances.
One of these notifications might be a property. I have several property files that I inject using the #Value annotation into the relevant Spring beans. These property files reside ina properties folder the class path root (classpath:properties/)
When operating on a single node, when I update a property, I update the in memory value using a setter and also write the change back to the relevant property file using FileInputStream and FileOutputStream. This is easy enough.
However, the obvious problem is now what happens when I autoscale and a new instance is started in a different container? This application will read the deployed (old) version of the property file and ultimately behave differently than the other parallel nodes.
I really would like to maintain file based configuration over a Database if I can - I know that the DB solution will be the most prevalent response here, but any suggestions would be appreciated.
Thanks
As far as you are already using JMS topics I'd suggest you to use durable subscription.
If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable TopicSubscriber. The JMS provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.
Take a look on JMS API: http://docs.oracle.com/javaee/6/api/javax/jms/Session.html#createDurableSubscriber(javax.jms.Topic, java.lang.String)

Categories