I have JBoss running on a couple of Linux machines. If I want to send a JMS message from box 1 to a queue on box2, I may do something like this:
Hashtable<String,String> jndiProperties = new Hashtable<String,String>();
jndiProperties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
jndiProperties.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
jndiProperties.put(javax.naming.Context.PROVIDER_URL, "jnp://<ip of box2>:1099"); //
InitialContext context = new InitialContext(m_jndiProperties);
Queue queue = (Queue)context.lookup("queue/myqueue");
and then put a message on the queue. Clearly port 1099 needs to be open on box2, but I am curious what other ports are involved in that communication?
Thank You.
Others I have off top of my head:
Rmi: 1098.
HornetQ acceptors / connectors: 5446 / 5445. Both configurable in JBOSS_HOME/server/default/deploy/hornetq/hornetq-configuration.xml
Related
It's amazing that i can't find a working example of how to send a message to a Wildfly 10 jms queue. It seems every version of Jboss had a different way of doing this so i can find a few examples but each one addresses a different version and none for Wildfly 10.
what I'm trying to do is send a message from a master wildfly instance (running on machine 1) to a JMS queue hosted on a slave wildfly instance (running on machine 2-n). In other words, i may have several slave wildfly instances.
I've added to the standalone-full.xml of each slave instance the following:
1) In the global-modules element
<module name="org.jboss.remote-naming" slot="main"/>
2) The queue is defined as
<jms-queue name="JobTaskMDB" entries="queue/JobTaskExecuterQueue java:jboss/exported/queue/JobTaskExecuterQueue"/>
3) Every slave has the guest user
The only thing I've added to the standalone-full.xml of the master instance is (1) above
Given a machine name, such as "WILDD250148-8C9", how can i selectively send a message from the master Wildfly instance to the queue of the specified machine hosting one of the slave instances?
So far I can't even get passed the lookup of the queue.
I've tried the following code:
String server = "WILDD250148-8C9";
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.SECURITY_PRINCIPAL, "guest"); //has been added to all slaves
env.put(Context.SECURITY_CREDENTIALS, "guest");
String url =
//"queue/JobTaskExecuterQueue";
//"http-remoting://" + server + ":8080";
//"tcp://" + server + ":5445";
"jnp://" + server + ":1099";
env.put(Context.PROVIDER_URL, url);
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
remoteContext = new InitialContext(env);
String lookupName =
//"java:jboss/exported/queue/JobTaskExecuterQueue";
//"JobTaskMDB";
"queue.queue/JobTaskExecuterQueue";
Object x = remoteContext.lookup(lookupName);
I always get "javax.naming.CommunicationException: Failed to connect to any server", for example
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [jnp://WILDD250148-8C9:1099 (No connection provider for URI scheme "jnp" is installed)]
or
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [tcp://WILDD250148-8C9:5445 (No connection provider for URI scheme "tcp" is installed)]
when I used the url "http-remoting://" + server + ":8080" I got the exception:
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [http-remoting://WILDD250148-8C9:8080 (Operation failed with status WAITING after 5000 MILLISECONDS)] [Root exception is java.net.ConnectException: Operation failed with status WAITING after 5000 MILLISECONDS]
Obviously i don't even know which provider URL to use.
what am i missing here?
The correct URL provider for WildFly 10 is http-remoting.
This works for me with Wildfly 10.1:
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
props.put(Context.SECURITY_PRINCIPAL, "user");
props.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
ActiveMQQueue queue = (ActiveMQQueue) ctx.lookup("queue/JobTaskExecuterQueue");
If the JNDI name of the queue is java:jboss/exported/queue/JobTaskExecuterQueue then from the client, use queue/JobTaskExecuterQueue (it's relative to the java:jboss/exported/ namespace)
Remove this line, this is not needed:
env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
If you're getting
Operation failed with status WAITING after 5000 MILLISECONDS
then it means that the connection got stuck for more than 5 seconds for some probably different reason, like a firewall, slow network or something - the client code is probably correct.
I have already working application based on Azure EventHub. Now I need write java receiver that connects to the existing infrastructure.
Existing configuration:
Event Hub > SomeName > Consumer Group > SomeGroupName
In the administrative console I cannot see any QUEUE or TOPIC definitions. Analyzing working c# code I can see that hub-name + group-name is enough to connect.
I have reconstructed url that allows me to connect over java (and connection works so far).
amqps://SomeName.servicebus.windows.net
So my questions:
1) When instead of queue /topic I specify group-name then I get exception The messaging entity 'sb://SomeName.servicebus.windows.net/SomeGroupName' could not be found. What is the model used there instead of queue/topic?
2) How to work with such infrastructure from Apache-qpid?
Are you using the Event Hub created in the old portal or one created using the new portal?
EventHub is not a Message Bus, so there are no Queues or Topics, that is correct.
The consumer group is not a part of the address. The address is build using the namespace and the name of the eventhub in that namespace.
So the address becomes:
sb://SomeNameSpaceName.servicebus.windows.net/SomeEventHubName
Can you post the c# code you've analyzed? Since you have an already working application maybe we can workout the differences that prevents it from working now.
The greatest hint for resolve the question gave me following link: http://theitjourney.blogspot.com/2015/12/sendreceive-messages-using-amqp-in-java.html
So No queue neither topic in this model. You need to connect to specific provider and specify correct EventHub as following:
application.properties:
connectionfactory.SBCF=amqps://<PolicyName>:<PolicyKey>#<DomainName>.servicebus.windows.net
queue.EventHub=<EventHubName>/ConsumerGroups/$Default/Partitions/0
Where:
After that following code allowed me to create MessageConsumer:
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
env.put(Context.PROVIDER_URL,
getClass().getResource("/application.properties").toString());
Context context = null;
context = new InitialContext(env);
// Look up ConnectionFactory
ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF");
Destination queue = (Destination) context.lookup("EventHub");
// Create Connection
Connection connection = cf.createConnection();
// Create receiver-side Session, MessageConsumer
Session receiveSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer receiver = receiveSession.createConsumer(queue);
The native JNI library 'mqjbnd64' not found.
please some one can help me to get mqjbnd64
this is my code
ConnectionFactory connectionFactory=null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/C:/CWMQv75-POT/JMS/JNDI Namespace");
try{
Context ctx = new InitialContext(env);
// MQQueueManager qm = (MQQueueManager)ctx.lookup("QM");
MQConnectionFactory cf = (MQConnectionFactory) ctx.lookup("CF1");
// cf.createConnection().start();
MQQueue q = (MQQueue) ctx.lookup("JMS1");
connectionFactory = (ConnectionFactory)ctx.lookup("CF1");
System.out.println("succes "+q.getBaseQueueManagerName().toString() + " " + q.getBaseQueueName()+" " +" " + cf.getChannel() );
} catch (NamingException e)
{
System.err.println(e.getLocalizedMessage());
e.printStackTrace();
}
Connection connection = connectionFactory.createConnection();
}
The native JNI library 'mqjbnd64' not found
Questions:
1) Are you running your JMS application on the SAME serer as the queue manager or a different server?
2) When you defined your QCF, did you include host, port #, channel name?
3) Do you understand the difference between connecting to a queue manager in bindings mode vs client mode?
You can ONLY connect in bindings mode if your application is running on the same server as the queue manager. When connecting in bindings mode the JMS/Java MQ library uses the native MQ library, hence, it needs the mqjbnd64 shared library or DLL on Windows to perform the MQ API calls.
Most MQ applications do NOT reside on the same server as the queue manager and they will use client mode to connect to the remote queue manager and your QCF would look something like:
DEFINE QCF(MYQCF) QMANAGER(MQWL1) CHANNEL(TESTCHL) HOSTNAME(10.10.10.10) PORT(1414) TRANSPORT(CLIENT) FAILIFQUIESCE(YES)
One other thing I noticed:
env.put(Context.PROVIDER_URL, "file:/C:/CWMQv75-POT/JMS/JNDI Namespace");
that should be:
env.put(Context.PROVIDER_URL, "file://C:/CWMQv75-POT/JMS/JNDI Namespace");
You should have 2 forward slashes "//" after "file:".
I am using apache's activemq for queueing. We have started to see the following exception very often when writing things to the queue:
Caused by: org.apache.activemq.transport.InactivityIOException: Cannot send, channel has already failed:
at org.apache.activemq.transport.AbstractInactivityMonitor.doOnewaySend(AbstractInactivityMonitor.java:282)
at org.apache.activemq.transport.AbstractInactivityMonitor.oneway(AbstractInactivityMonitor.java:271)
at org.apache.activemq.transport.TransportFilter.oneway(TransportFilter.java:85)
at org.apache.activemq.transport.WireFormatNegotiator.oneway(WireFormatNegotiator.java:104)
at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:68)
at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81)
at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1366)
I can't figure out what could be causing this-- or even, frankly, where to start debugging what is causing this.
Here is the queue set up code:
camelContext = new DefaultCamelContext();
camelContext.setErrorHandlerBuilder(new LoggingErrorHandlerBuilder());
camelContext.getShutdownStrategy().setTimeout(SHUTDOWN_TIMEOUT_SECONDS);
routePolicy = new RoutePolicy();
routePolicy.setCamelContext(camelContext);
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(queueUri);
// use a pooled connection factory between the module and the queue
pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
// how many connections should there be in the session pool?
pooledConnectionFactory.setMaxConnections(this.maxConnections);
pooledConnectionFactory.setMaximumActiveSessionPerConnection(this.maxActiveSessionPerConnection);
pooledConnectionFactory.setCreateConnectionOnStartup(true);
pooledConnectionFactory.setBlockIfSessionPoolIsFull(false);
JmsConfiguration jmsConfiguration = new JmsConfiguration(pooledConnectionFactory);
jmsConfiguration.setDeliveryPersistent(false); // do not store a copy of the messages on the queue
ActiveMQComponent activeMQComponent = ActiveMQComponent.activeMQComponent(queueUri);
activeMQComponent.setConfiguration(jmsConfiguration);
camelContext.addComponent("activemq", activeMQComponent);
Component activemq = camelContext.getComponent("activemq");
// register endpoints for queues and topics
Endpoint queueEndpoint = activemq.createEndpoint("activemq:queue:polaris.*");
Endpoint topicEndpoint = activemq.createEndpoint("activemq:topic:polaris.*");
producerTemplate = camelContext.createProducerTemplate();
camelContext.start();
queueEndpoint.start();
topicEndpoint.start();
Like I said, the error doesn't suggest any directions for debugging, and it doesn't happen in 100% of cases where I can be sure my configuration is not set up correctly.
Recently I ran into the same problem. I found this https://issues.apache.org/jira/browse/AMQ-6600
Apache ActiveMQ client throws InactivityIOException when one of the jars is missing in classpath. In my case it was hawtbuf-1.11.jar. When I added this jar to classpath it started to work without errors.
management port: 61616 (default)
service port : 8161(default)
change your broker url port to 61616 and run
refer this
Check, if there is a non-Jms client pinging your JMS broker. This may be an external monitoring tool, a load balancing tool such as keepalived, or another one.
I've set up ActiveMQ and I can create/connect to a topic using "dynamicTopics/MyTopic". This works great:
Properties env = new Properties( );
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
env.setProperty(Context.PROVIDER_URL,"tcp://myhostname:xxxxx");
javax.naming.Context ctx = new InitialContext(env);
InitialContext jndi = new InitialContext(env);
// Look up a JMS connection factory
TopicConnectionFactory conFactory = (TopicConnectionFactory)jndi.lookup("TopicConnectionFactory");
// Create a JMS connection
TopicConnection connection = conFactory.createTopicConnection(username,password);
Topic chatTopic = (Topic)jndi.lookup("dynamicTopics/MyTopic");
I would like to connect to a topic already exists without dynamically creating the topic if it doesn't exist, how can I do so?
Cheers,
Pete
While you don't need to create destinations manually with AMQ you always have that option. Basically you can alter the security settings to allow only an admin to create destinations. See the AMQ FAQ for this:
http://activemq.apache.org/how-do-i-create-new-destinations.html
Regards
Tim
www.fusesource.com
What you are actually doing is just connecting to topic. ActiveMQ is so nice that it creates topic for you if it did not exist before.
So, to connect to already existing topic just do the same that you are already doing.