Communicate between tomcat instances (Distributed Architecture) - java

We have a distributed architecture where our application runs on four Tomcat instances. I would like to know the various options available for communicating between these Tomcat instances.
The details : Say a user sends a request to stop listening to the incoming queues, this needs to be communicated with other Tomcat instances so that they stop their listeners as well. How can this communication be made across Tomcats?
Thanks,
Midhun

Looks like you are facing coordination problem.
I'd recommend you to use Apache ZooKeeper for this kind of the problems.
Consider putting your configuration to the ZooKeeper. ZooKeeper allows you to watch for the changes and if configuration was changed in ZooKeeper tomcat instance will be notified and you can adjust the behavior of your application on every node.
You can use any kind of external persistent storage to solve this problem, though.
Other possible way is to implement communication between tomcat nodes by yourself but in this case you'll have a problem with managing your deployment topology: every tomcat node should know about other nodes in the cluster.

what lies on the surface is RMI, HTTP requests. As well, IMHO, you could try to use MBeans. One more thing, you could use some non-java related things, like DBus or something, or even flat files... if all tomcats run on the same machine. Lots of options...

We use Hazelcast for this kind of scenario. They have an handy Http Session Clustering

Related

Is there a way to Queue REST call with Spring?

I am working on a project that is making a REST call to another Service to save DATA on the DB. The Data is very important so we can't afford losing anything.
If there is a problem in the network this message will be lost, which can't happen. I already searched about Spring Retry and I saw that it is designed to handle temporary network glitches, which is not what I need.
I need a method to put the REST calls in some kind of Queue (Like Active MQ) and preserve the order (this is very important because I receive Save, Delete and Update REST calls.)
Any ideas? Thanks.
If a standalone installation of ActiveMQ is not desirable, you can use an embedded in-memory broker.
http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html
Not sure if you can configure the in-memory broker to use KahaDB. Of course the scope of persistence will be limited to your application process i.e. messages in the queue will not be available if the application is restarted . This is probably the most important reason why in-memory or vanilla code based approaches are no good.
If you must reinvent the wheel, then have a look at this topic, which talks about using Executors and BlockingQueue to implement your own pseudo-MQ.
Producer/Consumer threads using a Queue.
On a side note, retry mechanism is not something provided by the MQ broker. It is the client that implements it. Be it ActiveMQs bundled client library or other Messaging libraries such as Camel.
You can also retrospect your current tech-stack to see if any of the existing components have JMS capabilities. For example: Oracle database bundles an MQ called Oracle AQ
Have your service keep its own internal queue of jobs, and only move onto the next REST call until the previous one returns a success code.
There are many better ways to do this but the limitation will come down to what your company will let you do.

Reusing Tomcat Tribes configuration to send messages between nodes

I have Tomcat session replication using static members tribe configuration in my server and it is working fine. However, I wanted to leverage the same setup in my application to send messages between members of the cluster to facilitate my event architecture my app uses. The reason I want to use this is for the following reasons:
Tribes is a peer to peer communication framework already built into tomcat.
Reuse the configuration of peers.
No need to add additional overhead of new libraries.
Is there a way to programmatically gain access to Tomcat's Cluster Channel object to send message over? Or is there a way to figure out the members of the cluster to create your own channel to minimize the need to duplicate configuration?
Here is an example of using JMX to find the cluster configuration. It's pretty hacky, but there might be an cleaner way to find this information in JMX.
http://www.coderanch.com/t/570194/Tomcat/find-Tomcat-cluster-members

Get current application instance using websphere api?

I've an app which is deployed on to a cluster with 2 jvms. The web application has cache implemented using Mbeans and the cache runs on each jvm. the cache is refreshed with a request pattern */refresh. The problem is that when the request goes through ODR, it routes it to only one server and the cache for only one server is refreshed. How do I solve this problem? Cache replication? I think it might be lot of work to implement cache replication. Any other solutions? Websphere api's ?
if I get the current instance of the application, I'm thinking of using AdminClient to get the clusters and then call the request on all the nodes on which the application is installed except for the current instance.
The Websphere way to do this is to use the DynaCache feature with DRS. The DynaCache is a kind of a hashmap, which can be distributed across the DRS cluster members. The dynacache has an API, DistributedMap, which extends the java.util.Map.
There are also a lot of configuration (Through AdminConsole and cachespec.xml) and monitoring possibilities (PMI with TPV).
Technical overview:
http://pic.dhe.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=%2Fliaag%2Fcache%2Fpubwasdynacachoverview.htm
DistributedMap API
http://pic.dhe.ibm.com/infocenter/adiehelp/v5r1m1/index.jsp?topic=%2Fcom.ibm.wasee.doc%2Finfo%2Fee%2Fjavadoc%2Fee%2Fcom%2Fibm%2Fwebsphere%2Fcache%2FDistributedMap.html
A good article from developerworks
http://www.ibm.com/developerworks/websphere/library/techarticles/0906_salvarinov/0906_salvarinov.html
The crude way we did something similar was to directly hit each Web Container on its own port. If you're able to reach them, that is.

Application using akka deployed in a weblogic cluster

I am currently developping an application which will be deployed in a weblogic application server cluster. This application is consuming some JMS messages through a MDB and process some business logic through AKKA actors.
Some of these agents are singleton and others are grouped in a pool and contact through a round-robin router.
I am trying to figure out how all these things will work in a clustered environment:
Is it possible to create a "unique" AKKA system even if the application is deployed on several nodes in the cluster? Do agents created on each server will known each other?
It it possible to add new weblogic node in the cluster and have AKKA framework recognize these new resources?
How configure all these things?
For what i see in AKKA documentation about the cluster implementation, it seems that the architecture supported is outside an application server, with AKKA nodes started from a java shell command.
Sadly, i have not found any valuable information on the use of AKKA in a application server environment.
Thanks for your help
When you say Akka agents, you mean actors? Also, I assume that round-robin dispatcher is a RoundRobinRouter :)
Akka does not have explicit support for application servers, but you should be able to instantiate an ActorSystem in your code.
As for "uniqueness", if you use clustering, the membership is maintained automatically for you so you can see which nodes are available, and you can add nodes easily. There is currently no naming service implemented on top of that, that is the target of a later version, so you have to take care of finding an actor inside the cluster yourself, or handling singletons global to the cluster.
I recommend reading the relevant sections in the documentation how you can set up and configure your cluster.
http://doc.akka.io/docs/akka/2.1.0/cluster/index.html

Java client for memcachedb with replication

I have one master and one slave memcachedb servers. I need some java client to memcache db with such opportunities:
At first it establishes connection to master server. In case if master fails the slave should become master and java client should reconnect to him. After the first server repairs they must work again in replication.
So, can you please help me to choose the best java client for memcachedb with such requirements?
Regards, Evgeniy
Spring Framework should contain support for memcached through the caching module. I know EhCache is supporter. If you are in Java, EHCache might be worth a look as it does not require that extra install process as memcached. Also, if Spring doesn't have an adapter, it should be simple to provide one to it, allowing you to switch caching implementations dynamically without changing code.
I have used xmemcached as a java client with several Memcached Servers working in paralell. (Not Master/Slave(
Just one question, when you say Memcached DB which is the purpose of using Memcached? A cache or a database?
Finally, I haven't found any solutions to work with several servers in replication mode. So if you want to have the same data on several nodes you should add it manually. Also in case of some server failure you should manually reconnect to another one.
Please, let me know if you found better solution.
Regards, Evgeniy

Categories

Resources