Wildfly hornetq clustering using static-connectors, Client fails to connect with errors related to JNDI lookup
meabhi007 Jun 24, 2016 5:13 PMHi,
I am trying to configure the HornetQ cluster using static connectors.
following are configuration for Cluster Node:
<subsystem xmlns="urn:jboss:domain:messaging:1.2">
...
<connectors>
<netty-connector name="netty-connector-cluster-node" socket-binding="jms-cluster-node"/>
</connectors>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty</connector-ref>
<static-connectors>
<connector-ref>netty-connector-cluster-node</connector-ref>
</static-connectors>
</cluster-connection>
...
</subsystem>
To connect standalone JMS Clients, i am using following piece of code.
Here in PROVIDER_URL i am providing the comma seperated values of JMS nodes.
public class JMSConnection
{
private static String topicConnectionFactoryName = "testConnectionFactory";
private static TopicConnectionFactory topicConnectionFactory;
private String initialContextFactoryName = "org.jboss.naming.remote.client.InitialContextFactory";
private String providerURL = "http-remoting://node1:9001,http-remoting://node2:9001";
private static InitialContext initialContext;
public JMSConnection() throws NamingException
{
Properties h = setContextProperty(initialContextFactoryName, providerURL);
initialContext = new InitialContext(h);
}
/**
* @param args
* @throws NamingException
*/
public static void main(String[] args) throws NamingException
{
new JMSConnection();
initialContext.lookup(topicConnectionFactoryName);
}
public static Properties setContextProperty(String contextFactory, String providerUrl)
{
Properties prop = new Properties();
// For Jboss 7 on App Server these properties are passed as blank so we don't need to set
// them.
prop.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
prop.put(Context.PROVIDER_URL, providerUrl);
prop.put("jnp.disableDiscovery", System.getProperty("jboss.global.jnp.disableDiscovery", "true"));
return prop;
}
}
UseCases:
1. Node-1 - Active and Node-2 Backup
In this case, JNDI lookup works fine and i get the reference of connection factory.
2. Node-1 Backup and Node-2 Active
In this case, JNDI lookup is throwing NamingException that connection factory is not found.
What i understand here that Since Connection factory is registered into Node-2, while Provider-url is having 1st entry for Node-1 (which is running in backup mode and doesn't have connection factory registered).
Since Node-1 is up and running so JNDI lookup manages to make connection with node-1 and doesn't find connection factory registered, so throws an exception.
Can someone please suggest the better way to write the Clients for this scenario, or there is something, which can be done in Wildfly configurations for hornetQ server.?
even MDB clients are failing to find out the active node.
<jee:message-driven>
<jee:ejb-name>Topic1</jee:ejb-name>
<jee:activation-config>
....
...
<jee:activation-config-property>
<jee:activation-config-property-name>hA</jee:activation-config-property-name>
<jee:activation-config-property-value>true</jee:activation-config-property-value>
</jee:activation-config-property>
<jee:activation-config-property>
<jee:activation-config-property-name>connectionParameters</jee:activation-config-property-name>
<jee:activation-config-property-value>host=node1;port=5445,host=node2;port=5445</jee:activation-config-property-value>
</jee:activation-config-property>
...
...
</jee:activation-config>
</jee:message-driven>
Note: I didn't see this kind of issue with Multicast based clustering configurations, but i can't use multicast based clustering, since it will not be supported with Amazon Cloud.
Thanks in advance.