0

I am using Glassfish 3.1.2, and I set up a cluster with one node and two instances.

I have an message driven bean in my application that subscribes to a topic, which I deployed to the cluster.

When I publish a message to the topic I want both instances to receive the message.

However, in practice I am finding that only one instance receives the message.

I believe I am running into a feature called "shared subscriptions" http://docs.oracle.com/cd/E18930_01/html/821-2438/gjzpg.html#MQAGgjzpg

The feature (which is enabled by default) says that beans in the cluster with the same client id are shared, and are effectively only one subscription.

It says that by default the client id of an MDB is its name, which means that both my instances are using the same client id.

So other than completely disabling this feature, I would like to know if it is possible to setup an MDB so that each instance subscribes with a different client ID? This seems a bit tricky since both instances are using the same WAR file. I think you can set the client ID in an annotation, but I'm not sure if that can be changed at runtime...

Dan Metheus
  • 1,418
  • 9
  • 16
Darren
  • 722
  • 4
  • 12

1 Answers1

0

I'm not sure why you would completly disable this feature. In the link you provided, it states clearly that you configure this per ActivationSpec/MDB. So as far as I understand it, it would affect only the MDB you have at hand.

For an MDB, set the ActivationSpec property useSharedSubscriptionInClusteredContainer to false. Do this in exactly the same way as with other ActivationSpec properties, using annotations in the MDB itself or in the deployment descriptor ejb-jar.xml or glassfish-ejb-jar.xml.

But you can of course set the client ID on a connection dynamically during runtime. Please note that you probably would have to handle the JMS connection yourself a bit more than relying on the features managed by the container.

http://docs.oracle.com/javaee/6/api/javax/jms/Connection.html#setClientID(java.lang.String)

MaDa
  • 10,511
  • 9
  • 46
  • 84
Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • Thanks, but I'm not sure how to get access to the underlying connection of the MDB, nor how to set the ActivationSpec property (can this be done using an annotation?) BTW my approach for now that does work is to use the following annotation: @ActivationConfigProperty(propertyName = "clientID", propertyValue="${com.sun.aas.instanceName}") This seems to set a different client id for each instance. – Darren Mar 08 '13 at 14:29