Notification system in spring web app - java

I am currently developing java/jee application,which has 2 projects:backend and frontend projects which are communicating via micro services.I am using mysql as database and i want to create a notification system so what is recommended to be used?

There are 3 options.
JMS/ActiveMQ with JMSTemplate
AMQP/RabbitMQ or Kafka with RabbitTemplate/KafkaTemplate (Preferred for beginners)
Spring Cloud Stream with Kafka (High throughput/Advanced usecase microservices)
More here for AMQP
More here for Cloud Stream.
If you're starting out it's fine using the second option. It's easy to migrate to the third one and you should be using Spring Cloud (specially designed for microservices) for that. The third one is the easiest and have lesser codes.

Related

Implementing Kafka inside a Java Client Library

I have a back-end application which is exposing APIs and for my clients to consume. Till now the requirement was only from Direct Frontend Dashboards. Recently I have got a client for my service that wants to consume these Apis on his backend application.
I am planning to build a client library in java for the same, which calls my APIs, and has a build in-memory cache system. Till this point everything is clear, but i want my client to have kafka as well. One way is that the backend application that wants to consume this api has Kafka Listener inside his application, the other idea that came across my mind is that what if I cant build a kakfa listner inside my client library itself. Is it a good idea to do it? Assuming that Kafka config will be present inside the backend application that is going to use my client library?
Kafka is a backend service. If you are providing your own REST APIs for clients, then that is not used by a Spring #KafkaListener.
If you add your own #KafkaListener, then you could store that data into your own app and expose data via HTTP endpoints, sure.
But that still wouldn't solve how external services plan on using Kafka on their own. If both services are connected same Kafka cluster, then you don't need HTTP endpoints, rather you would use KafkaTemplate to send data to Kafka, after which the external service would consume via their own #KafkaListener

Java - Is it Possible to Use Spring Cloud Stream Kafka and RabbitMQ for the Same Application

We have an application that is already using Spring Cloud Stream with RabbitMQ, some endpoints of the application are sending messages to Rabbit MQ. Now we want new endpoints start sending messages to Kafka, hoping that the existing endpoints continue using RabbitMQ with Spring Cloud Stream. I am not sure if this is even possible, because this means we have to include both kafka and rabbit binder dependencies in pom.xml. What configuration changes we need to make in the yml file so that the app understands what bindings are for kafka and what bindings are for Rabbit? Many thanks.
Yes it is possible. This is what we call a multi-binder scenario and is one of the core features specifically to support the use case you are describing.
Here is where you can find more information - https://docs.spring.io/spring-cloud-stream/docs/3.2.1/reference/html/spring-cloud-stream.html#multiple-binders
Also, here is an example that actually provides configuration that uses Kafka and Rabbit. While example is centered around CloudEvent, you can ignore it and strictly concentrate on configuration related to Rabbit and Kafka binders - https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-cloudevent-stream
Feel free to ask follow up questions once you get familiar with that.

Testing tools for Apache Kafka performance

I am new in Kafka,I have create a spring boot application, in this application consumes messages from kafka topics, processes it and stores in Database.
I tried Jmeter pepper box for this but it can't work for me properly.
So please any one can suggest me other best tool or list of kafka testing tools for test end to end my spring boot code with Kafka performance or best example of pepper box,I preferred this link :- https://www.blazemeter.com/blog/apache-kafka-how-to-load-test-with-jmeter

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.

Architecting RESTful app ... out of ... Java Web app

Our current Web Application Architecture consists of following :
Java 6, JBOss 5, MySQL 5.6
Presentation Layer (ZK Framework)
Delegate + Service + DAO Layers (Spring & Hibernate)
Packaging : Single War file containing all the above layers
Business Requirement :
Create mobile app for few modules of above mentioned web application, using HTML5 and Native iOS library.The mobile app would be able to perform CRUD, download/upload files and send emails.
Question :
We are in the process to determine the architecture for the above business requirement. Keeping in mind the following attributes
Data Logic sharing (Implemented in DAO layer using Hibernate)
Business Logic sharing (Implemented in Service layer using Spring)
QoS - Performance, Scalability
Some of our thoughts :
Create a separate delegate layer within the web app and expose it as a REST API. The underlying, objects of service and DAO layer can be used as it is.
Will need to scale application, to handle the load of both web app and mobile app !
Create a common project (Jar) for common functionalities, and share it with 2 different project, one for web app, and the other for mobile-app.
Will Hibernate will be OK , to share the same database with 2 applications, without any concurrency issues ?
I would really appreciate any advice/opinion about the above.
Thanks
In my opinion, you should сonsider using of the MQ systems (RabbitMQ e.g.) and split your app in 3 layers:
Frontend - accepts client requests (one for browsers, second for mobile apps etc.) and transmit them to MQ.
Intermediate (transport) - MQ system. Transports messages.
Backend - accepts inbound messages from MQ, processes request and gives the answer back.
This is what you described in 2nd option. But i think it would be better to have intermediate layer (MQ) to avoid coupling.
I think Hibernate needs to be configured with distributed 2nd level cache (EhCache e.g.), to make backend scalable.
With this architecture you can simple scale throughput of your app by adding backend server and subscribing it on queue in MQ.

Categories