Switchyard Camel JMS binding to Remote Topic

Latest response

Howdy!

Now trying to take swithcyard-quickstart-camel-jms-binding and modify it to upon initialization create a HornetQ remoting client consumer/subscriber connection to, well, a remote EAP-5 HornetQ server. Seems like it would be an 'advanced details Additiona URI Parameter", adding java.naming.provider.url jnp://192.168.235.140:1099 but this failes XSD validation. Then tried various configurations from http://camel.apache.org/jms, such as Using JNDI to find the ConnectionFactory... just not finding the secret ingredients again.

Sincere thanks!

John

Attachments

Responses

Guess while I'm at it... on the 'other end' of the flow, I also need a reference that is a publisher to a remote... ???

Hi John! I'll see if I can find someone who can help you with this. Cheers, Ben.

John, I am told that you could try to lookup the ConnectionFactory and set it on a camel JmsComponent; for example:

@Produces @Named("jms")
public JmsComponent create() {
JmsComponent jms = new JmsComponent();
jms.setConnectionFactory(new InitialContext(remoteJndiProps).lookup("/MyRemoteConnectionFactory"));
return jms;
}

Let me know if this helps.

Howdy! Sincere thanks for the reply. I've created a class following your snippet and in my switchyard.xml used the name within @Named("xxxx") as the jms:connectionFactory (uploaded entire project)

Class:
public class MAPSConsumer {
String hostName = "192.168.235.140";

@Produces
@Named("Block1_TS1")
public JmsComponent create() {
JmsComponent jms = new JmsComponent(); 

....

switchyard xml

<jms:binding.jms>
SMM_UI
Block1_TS1
</jms:binding.jms>

Sadly, it errors on the lookup:
org.switchyard.SwitchYardException: org.apache.camel.FailedToCreateRouteException: Failed to create route V1CamelJmsBindingModel/GreetingService@_GreetingService_jms_1#-1672298836: Route[[From[jms:topic:SMM_UI?connectionFactory=Block1_TS1]] ... because of Failed to resolve endpoint: jms://topic:SMM_UI?connectionFactory=Block1_TS1 due to: Cannot lookup: Block1_TS1 from registry:

Will add log to discussion too.

Thanks!

Hi John!

@Named("Block1_TS1") should be @Named("jms"), otherwise camel doesn't use it to create jms component.

And I am told that this does not look like valid configuration:

<jms:binding.jms>
SMM_UI
Block1_TS1
</jms:binding.jms>

The SME I'm working with can't quite understand what you want to do here.

Cheers,
Ben

Morning. Thank you. I changed back to @Named("jms") and service is now:

<jms:binding.jms>
SMM_UI
#ConnectionFactory
</jms:binding.jms>

At least I'm getting a compile, albeit an error trying to subscribe to remote topic:
09:00:00,762 INFO [org.switchyard.common.camel.SwitchYardCamelContext] Route: V1CamelJmsBindingModel/GreetingService@_GreetingService_jms_1#2028581883 started and consuming from: Endpoint[jms://topic:SMM_UI?connectionFactory=%23ConnectionFactory]
09:00:00,777 INFO [org.apache.camel.impl.DefaultShutdownStrategy] Starting to graceful shutdown 1 routes (timeout 30 seconds)
09:00:05,803 WARN [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] Setup of JMS message listener invoker failed for destination 'SMM_UI' - trying to recover. Cause: There is no topic with name SMM_UI
09:00:05,803 INFO [org.apache.camel.impl.DefaultShutdownStrategy] Route: V1CamelJmsBindingModel/GreetingService@_GreetingService_jms_1#2028581883 shutdown complete, was consuming from: Endpoint[jms://topic:SMM_UI?connectionFactory=%23ConnectionFactory]
09:00:05,803 INFO [org.apache.camel.impl.DefaultShutdownStrategy] Graceful shutdown of 1 routes completed in 5 seconds

What I am trying to do is, upon start of the system, the JMS service will subscribe to a remote Topic and as messages are published, become part of the defined route.

Seems like this solution is a system-wide override of the ConnectionFactory. My design requirement is to be able to connect to 5 different topics on 5 different servers as subscribers. I cannot change the system I'm integrating with to create a topic or queue publisher into my switchyard, thus the need for my JMS Camel binding to create the remoting connection itself.

Hi John,

Glad to hear it's compiling now :)

Since this one is getting more complicated, for further assistance, I recommend lodging a support ticket. Please let me know if you would like any assistance with this process.

Regards,
Ben

Thanks. Created Case 01406480

No problem, Thank you, John!

We were close... so wanted to share the answer support came up with:
Hello. We finished creating a test program and confirmed the idea.

JMS service binding can subscribe a remote HornetQ Queue/Topic, and you can do the setting/implementation on JBoss Developer Studio. This is the instruction:

1: To inject javax.jms.ConnectionFactory Object which is the one for remote HornetQ, create a Producer Class
Please check the sample code[1], if you need

2: For the "Connection Factory" property of JMS Service binding, Please set the Producer name with '#'
Please check the sample setting[2], if you need

So you can create multiple JMS Service bindings which connect to x different remote servers, and on each subscribe to y different topics.
Please let us know if you have any question. Otherwise, please simply close this case.

[1] This is just a sample code to provide an idea

@Produces @Named("namedRemoteConnectionFactory")
public ConnectionFactory create() {
    try {
        final Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        env.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
        env.put(Context.SECURITY_PRINCIPAL, "username");
        env.put(Context.SECURITY_CREDENTIALS, "password");
        InitialContext ic = new InitialContext(env);
        return (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory");
    }
    catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}

[2] switchyard.xml

<sca:service name="GreetingService" promote="GreetingService/GreetingService">
  <jms:binding.jms>
    <jms:queue>GreetingServiceQueue</jms:queue>  // If you want to subscribe a topic, you can fix this part
    <jms:connectionFactory>#namedRemoteConnectionFactory</jms:connectionFactory>
  </jms:binding.jms>

Hi John!

Thank you so much for returning here to share the solution. Much appreciated. You are an ideal customer :)

Regards,
Ben