How do Applications are being notified by Gemfire - spring

In a web application that uses Gemfire to store their Session (Spring Session - an implementation of HTTPSession), how does Gemfire notify the changes (like cache expiry, cache change, cache destry..events) ? especially when Gemfire is deployed in a Client-Server model or Peer-to-Peer model..etc. the event might get triggered in any one node in the entire distributed environment, we might not want to keep listening to all the nodes..etc.
I see Gemfire has MBeans which emits notifications, should our application hook listeners to these MBean notifications or is there any other better way ?
The purpose is to put some clean-up code during such events.

you could use the GemFire event listener model approach whereby each node would listen for events (poll - sorta), rather than have the source 'push' to each node. in GemFire, have a look at the ContinuousQueryListener (Spring Integration Example or Spring Data GemFire docs) to enable you to subscribe to events.

Related

Kafka as event source when using Axon

I'm studying Axon framework to try to use it in one of my microservices. I use Spring boot as my microservice and I want to use Axon framewrok for DDD and event sourcing. The thing is we already use Kafka in production and I'm not sure I can add another service (Axon serve) since it might consume resources I don't have (does it consume a lot of resources by the way?)
So I was thinking to use Kafka as event source and event routing with Axon.
Is it possible?
You can use Kafka as event bus using the Kafka extension for Axon. You can't use Kafka as event store however. So you still need Axon Server or a relational database for the event store to use Axon Framework.
You could also combine those, e.g. have some events via Kafka, and some via Axon Server.

Create and cleanup instance specific rabbitMQ instances

I have a set of microservices using springboot rest. These microservices will be deployed in a autoscaled and load balanced environment. One of these services is responsible for managing the system's configuration. When other microservices startup, they obtain the configuration from this service. If and when the configuration is updated, I need to inform all currently running microservices instances to update their cached configuration.
I am considering using RabbitMQ with a fanout exchange. In this solution, each instance at startup will create its queue and bind that queue to the exchange. When there is a configuration change, the configuration service will publish an update to all queues currently bound to that exchange.
However, as service instances are deleted, I cannot figure out how would I delete the queue specific to that instance. I googled but could not find a complete working example of a solution.
Any help or advise?
The idea and solution is correct. What you just miss that those queues, created by your consumer services could be declared as auto-delete=true: https://www.rabbitmq.com/queues.html. As long as your service is UP, the queue is there as well. You stop your service, its consumers are stopped and unsubscribed. At the moment the last consumer is unsubscribed the queue is deleted from the broker.
On the other hand I would suggest to look into Spring Cloud Bus project which really is aimed for tasks like this: https://spring.io/projects/spring-cloud-bus.

What is the correct way to run a non-API service in Quarkus?

I understand Quarkus owns the main thread, but there doesn't seem to be a clean way to start a service that doesn't provide REST endpoints. I have a service that connects to a data source and writes the data stream to a database, with no API. The best solution I can find is to observe the startup event:
fun onStart(#Observes event: StartupEvent)
And then inject an instance of my service and start it there.
Any better suggestions?
What is your use case ?
There are many ways to start up a service:
- listening to system/CDI events like you did,
- using a scheduler (see Quarkus guide),
- using messaging like JMS or Kafka by listening to incoming messages,
- using Apache Camel you can trigger your service by listening to almost anything like: jms, files, timers, email, etc.

Spring Session with hazelcast session events firing

I am using Spring Session with Hazelcast and Spring Websockets. As I don't need clustarization I use hazelcast with MapSessionRepository. But it doesn't fire event on session expiring or session deleting. What I want is to listen to SessionExpiredEvent and then disconnect user via websocket immediately. So I have two problems:
MapSessionRepository does not firing needed events (SessionExpiredEvent and etc.)
I don't realize how to send websocket notification using expired http session. I need something like simpMessageTemplate.convertAndSendToUser().
But how I can get the user?
So the only one variant I can see is to write own implementation for SessionRepository<ExpiringSession> with events firing. I hope you understood my question. Thanks in advance.
Spring Session Hazelcast support does provide publishing of session events. The functionality itself is implemented using SessionEntryListener so make sure you use #EnableHazelcastHttpSession annotation which configures all the necessary components for Hazelcast integration.
It might also be of your interest that the upcoming Spring Session 1.3 (currently at 1.3.0.M2) will provide first-class Hazelcast support with new HazelcastSessionRepository (which will, among other things, replace SessionEntryListener).

communication between spring instances behind a load balancer

I have a few instances of Spring apps running behind a load balancer. I am using EHCache as a caching system on each of these instances.
Let's say I receive a request that is refreshing a part of the cache on one instance. I need a way to tell the other instances to refresh their cache (or to replicate it).
I'm more interested in a solution based on Spring and not just cache replication and that's because there are other scenarios similar with this one that require the same solution.
How can I achieve this?
There is no simple Spring solution for this. Depends on the requirements. You can use any kind of PubSub like a JMS topic to notify your nodes. This way the problem can be that you cannot guarantee consistency. The other nodes can still read the old data for a while. In my current project we use Redis. We configured it as cache with Spring Data Redis and theres no need to notify the other nodes since the cache is shared. In non cache scenarios we also use redis as a PubSub service.

Resources