If I send a message to a Distributed Queue, I have no control on which specific instance of the Queue, on which JMSServer, the message will go.
When you target a Distributed Queue "MyQ" to a cluster, this gets created in the JNDI tree of each Managed Server in the cluster:
The Distributed Queue:
Class: weblogic.jms.common.DistributedDestinationImpl
Binding Name: jms.jndi.dq.MyQ
The actual instance in the JMSServer running in the Managed Server:
Class: weblogic.jms.common.DestinationImpl
Binding Name = CommonJmsServer1@jms.jndi.dq.MyQ
So, you must bind to "CommonJmsServer1@jms.jndi.dq.MyQ" to send to only that JMSServer.
Example of WLST script to send to multiple physical destinations:
from javax.naming import Context, InitialContext
from weblogic.jndi import WLInitialContextFactory
from javax.jms import QueueSession, Queue, Session
msservers=["myhost1:8001", "myhost2:8001", "myhost3:8001", "myhost4:8001"]
jmsservers=["CommonJmsServer1", "CommonJmsServer2", "CommonJmsServer3", "CommonJmsServer4"]
jmsQueueJNDIs=["jms.jndi.dq.AQ", "jms.jndi.dq.BQ"];
for i in range(len(msservers)):
msserver = msservers[i]
jmsserver = jmsservers[i]
properties = Properties()
properties[Context.PROVIDER_URL] = "t3://" + msserver
properties[Context.INITIAL_CONTEXT_FACTORY] = WLInitialContextFactory.name
print "connecting to " + msserver + "..."
ctx = InitialContext(properties)
print "successfully connected to ", msserver
connectionFactory = ctx.lookup("weblogic/jms/XAConnectionFactory" )
queueCon = connectionFactory.createQueueConnection();
queueSession = queueCon.createQueueSession( false, Session.AUTO_ACKNOWLEDGE );
for jmsqueue in jmsQueueJNDIs:
theJNDI = jmsserver + "@" + jmsqueue
queue = ctx.lookup(theJNDI)
sender = queueSession.createSender( queue );
msg = queueSession.createTextMessage( "I am a pig " );
msg.setStringProperty("ISTEST", "true");
print "sending message to " + theJNDI
sender.send( msg );
See also:
http://www.javamonamour.org/2011/09/creating-durable-subscribers-for.html
No comments:
Post a Comment