使用Spring集成连接到IBM MQ的Java配置
答案 0 :(得分:0)
请使用以下代码使用Java配置创建入站消息驱动通道适配器。
@Value("${jms.queuemanagername}")
private String queuemanagername;
@Value("${jms.hostName}")
private String hostName;
@Value("${jms.port}")
private String port;
@Value("${jms.channel}")
private String channel;
@Value("${jms.queueName}")
private String queueName;
@Autowired
public AmqpTemplate amqpTemplate;
@Bean
public MessageChannel queureader() {
return new DirectChannel();
}
public static void main(String[] args) {
SpringApplication.run(IbmMqConnectorApplication.class, args);
}
@Bean
public IntegrationFlow ibmInbound() {
return IntegrationFlows.from(Jms.messageDrivenChannelAdapter(getConnection()).destination(reciverBean()))
.channel("queureader")
.get();
}
@Bean
public MQQueueConnectionFactory getConnection() {
MQQueueConnectionFactory connection = new MQQueueConnectionFactory();
try {
connection.setTransportType(1);
connection.setQueueManager(queuemanagername);
connection.setHostName(hostName);
connection.setPort(Integer.parseInt(port));
connection.setChannel(channel);
} catch (Exception e) {
System.out.println("Error");
}
return connection;
}
@Bean
public MQQueue reciverBean() {
MQQueue queue = new MQQueue();
try {
queue.setBaseQueueManagerName(queuemanagername);
queue.setBaseQueueName(queueName);
} catch (Exception ex) {
System.out.println("Error");
}
return queue;
}
@ServiceActivator(inputChannel = "queureader")
public void Print(Message<?> msg) {
System.out.println(msg.getPayload().toString());
}
确保您在pom.xml中添加以下依赖项
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mqjms</artifactId>
<version>5.3.07</version>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.disthub2.dhbcore</artifactId>
<version>7.1.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.ibm/com.ibm.mq -->
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq</artifactId>
<version>5.3.07</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.resource/connector-api -->
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector-api</artifactId>
<version>1.6-alpha-1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.ibm/com.ibm.mq -->
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq</artifactId>
<version>5.3.07</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.resource/connector -->
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
请为连接详细信息设置各自的值。谢谢!!!