Another task with not enough documentation and examples.
I did find this
stackoverflow post helpful.
This
post was also helpful but not quite correct. You don't need the custom JndiTemplate and the url should be the path to the directory where the bindings file is installed not the path to the file itself.
This assumes that you have installed the
.bindings
file in
/var/mqm
. Essentially, you are making the filesystem your jndi store.
It is also important to use the correct version of the IBM MQ libraries. We started using the 8.0.0.4 version of the libraries to connect to a 7.1 server and found the the connection name was being set improperly on the mq server. Getting the right libraries fixed the problem.
@Bean
public JndiTemplate jndiTemplate() {
Properties jndiProps = new Properties();
jndiProps.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
jndiProps.setProperty("java.naming.provider.url", "file:///var/mqm/");
JndiTemplate jndiTemplate = new JndiTemplate();
jndiTemplate.setEnvironment(jndiProps);
return jndiTemplate;
}
@Bean
public JndiObjectFactoryBean jmsConnectionFactory() {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiTemplate(jndiTemplate());
jndiObjectFactoryBean.setJndiName("CONNECTIONFACTORY");
return jndiObjectFactoryBean;
}
@Bean
public JndiObjectFactoryBean jmsTopicName() {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiTemplate(jndiTemplate());
jndiObjectFactoryBean.setJndiName("YOURTOPICNAME");
return jndiObjectFactoryBean;
}
@Bean
public IntegrationFlow jmsInboundFlow() throws Exception{
return IntegrationFlows
.from(Jms.messageDrivenChannelAdapter((ConnectionFactory)jmsConnectionFactory().getObject())
.destination((Destination) jmsTopicName().getObject())
.configureListenerContainer(c -> { c.pubSubDomain(true); c.subscriptionDurable(true); }))
.handle(CharacterStreamWritingMessageHandler.stdout())
.get();
}
No comments:
Post a Comment