How to implement cache synchronization in tomcat 6.0 cluster environment? - caching

I'm currently working on a migration a web application to run in a cluster. This application uses caches. Some of this caches are reloaded in case the user saves something. I'ld like to inform the other nodes of the cluster about this, so that all nodes refresh their caches.
It seems that the tomcat server has a group messaging build in. (Tribes)
I'm wondering if I can use this messaging for my task and how to have the event listener run the whole day then.
with kind regards
Michael

It is possible to use it and there is no need to start a thread or the like.
Sending class instances around requires a jar of the message class in tomcat lib directory.
cheers
Michae

You can use Hazelcast Topic. It is a very lightweight pub/sub messaging. Each node will listen to the topic. When user saves smth on any node just put some message "REFRESH". On receive each node can do whatever you want.
Here is the code to do this:
String REFRESH = "REFRESH";
ITopic<String> topic = Hazelcast.getTopic("myTopic");
topic.addMessageListener(new MessageListener<String>() {
public void onMessage(String msg) {
if(REFRESH.equals(msg){
//do refresh
}
}
});
//when user saves sth.
topic.publish(REFRESH);

If you are using handwritten CACHE, Than you can synchronize cache B/W all nodes of cluster using message broadcasting/receiving , You can use JGROUP for that.
for ex: node A update cache that it just broad cast message to other node to refill(refresh) their cache

Related

ActiveMQ How to delete only some scheduled elements

I have an ActiveMQ messaging system and i want to delete only some scheduled messages from the queue.
I can delete all the scheduled message via a ScheduledMessage.AMQ_SCHEDULER_ACTION_REMOVEALL
message sent to the queue.
I can delete a message by ID by sending a AMQ_SCHEDULER_ACTION_REMOVE message.
But is there a way to delete all messages with a selector (maybe a property on the message) ?
I checked the Jolokia REST API of ActiveMQ, but it seems that informations on Scheduled messages are not available.
No that functionality is not currently supported. You would need to take a look at the source code and implement this yourself and then contribute it back to the community. There is a fine line though were trying to use a message broker as a database will turn around and bite you so I'd recommend caution on that front.
You'd need to implement a new remove directive like AMQ_SCHEDULER_ACTION_REMOVE_SELECTED and define how the selector works in that case, SQL92 string etc and then add an API on the Scheduler store interface and implement it in the Scheduler implementation in the KahaDB module.

Spring boot applications high availability

We have a microservice which is developed using spring boot. couple of the functionalities it implements is
1) A scheduler that triggers, at a specified time, a file download using webhdfs and process it and once the data is processed, it will send an email to users with the data process summary.
2) Read messages from kafka and once the data is read, send an email to users.
We are now planning to make this application high available either in Active-Active or Active-passive set up. The problem we are facing now is if both the instances of the application are running then both of them will try to download the file/read the data from kafka, process it and send emails. How can this be avoided? I mean to ensure that only one instance triggers the download and process it ?
Please let me know if there is known solution for this kind of scenarios as this seems to be a common scenario in most of the projects? Is master-slave/leader election approach a correct solution?
Thanks
Let the service download that file, extract the information and publish them via kafka.
Check beforehand if the information was already processed by querying kafka or a local DB.
You also could publish an DataProcessed-Event that triggers the EmailService, that sends the corresponding E-Mail.

Cache values in Java EE

I'm building a simple message delegation application. Messages are being send on both ends via JMS. I'm using a MDB to process incoming messages, transform them and send them to a target queue. Unfortunately the same messages can be send to the incoming queue more than once but it is not allowed to forward duplicates.
So what is the best way to accomplish that?
Since there can be multiple MDBs listening on the incoming queue a need a single cache where I can store the unique message uuids of the incoming messages for at least an hour. How should this cache be accessed? Via a singleton/ static class (I'm running Java EE 5 and thus don't have the singleton annotation)?
In addition I think all operations must be synchronized, right? Does that harm performance too much?
#Ingo: are you OK with database solution. You can full fledged DB server or simple apache derby solution for this..
If so, you can have a simple table where you can store message unique UId and can check against it for uniqueness....this solution will have following benefits:
Simple code
No need of time bound cache(1 hour). You can check for uniqueness of a message forever.
Persistent record of what messages came in.
No need of expensive synchronized, you can rely on DB isolation level to have consistency.
centralized solution for your possibly many deployments of application.

Using Filters to control message delivery in a HornetQ cluster?

Due to business requirements, I'm working with a JMS messaging setup in which:
Queues must be defined by the application container.
Queues must be able to exist in a cluster, and balance load.
The application must allow the client to specify a subset of cluster nodes that may receive messages from this queue.
Currently every node has an identical hornetq configuration, and each node communicates with the default broadcast setup.
After reading the documentation, I had the thought that I could perhaps set a property on the message that includes a list of legal cluster nodes, then do something along the lines of 'position(${currentNode}, LEGAL_NODES) != 0'. So far I haven't had much success, mostly due to fairly spotty documentation in the hornetq documentation.
Has anyone solved a problem like this? How did you do it?
I ended up using this selector on each queue:
<selector string="LEGAL_NODES LIKE '%${cluster_identifier}%' OR LEGAL_NODES = ''"/>
After that, I used a Spring MessagePostProcessor to set the LEGAL_NODES property for each message.

MSMQ write taking > 1 minute

We have an ongoing problem with message writes to MSMQ being very slow. Our queue is on Windows Server 2008 SP2. The queue is a public queue, addressed at "servername\queuename".
The code to send a message to the queue is
MessageQueue queue = new MessageQueue(Settings.Default.DefaultDestinationQueue);
queue.Formatter = new BinaryMessageFormatter();
queue.Send(message);
The message that we're trying to send is simply a "PublishMessage", as follows:
[Serializable]
public class PublishMessage {
public int EntryId {get; set; }
}
We're seeing the messages actually reach the queue, but logging before and after shows that it's generally taking in excess of 1 minute for each message.
At this time, we can't see anything wrong with our queue configuration, but are not queuing experts--this is the first addition to this application. Anyone have any ideas?
Edit: Our server is running SP 2 (not SP1 that I originally stated). Running an instance directly on the machine hosting the queue is fast, any other is not.
Note: Crossposted this at https://serverfault.com/questions/272242/msmq-write-taking-1-minute
Our problem turned out to be an infrastructure issue with servers not properly authenticating. Our sysadmin finally got it straightened out by reconfiguring the server hosting the queue.
Is the queue transactional or non-transactional? Try toggling this setting and see if you get the same behavior.
How much space is allocated for the queue? Try increasing the space, and/or moving its storage to a different drive (on a different physical spindle).
Are there messages in the system queues? Check the system queues for messages. Also, try purging all the messages from the system queues and re-run.

Resources