首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IBM-MQ创建MQ目的地

IBM-MQ创建MQ目的地
EN

Stack Overflow用户
提问于 2019-04-08 06:23:59
回答 1查看 891关注 0票数 0

使用spring引导和IBM,我需要向MQ发送消息。

在我的Spring应用程序中,我注册了MQQueueConnectionFactory,如下所示。

代码语言:javascript
复制
@SpringBootApplication
@EnableJms
public class MainApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(MainApplication.class).web(WebApplicationType.NONE).run(args);
        logger.info("init completed...");
    }

    @Bean
    public MQQueueConnectionFactory queueConnectionFactory() {
        MQQueueConnectionFactory queueConnectionFactory = new MQQueueConnectionFactory();
        try {
            queueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
            queueConnectionFactory.setHostName(host);
            queueConnectionFactory.setChannel(channel);
            queueConnectionFactory.setPort(port);
            queueConnectionFactory.setQueueManager(queueManager);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return queueConnectionFactory;
    }

}

我有如下所示的目的地解析器。

代码语言:javascript
复制
 @Component
 public class IBMWebSphereMqDestinationResolver extends 
  DynamicDestinationResolver implements DestinationResolver {

@Override
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException {
    Destination destination = super.resolveDestinationName(session, destinationName, pubSubDomain);
    if (destination instanceof MQDestination) {
        MQDestination mqDestination = (MQDestination) destination;
    }
    return destination;
}

}

我使用JmsTemplate向MQ发送消息。

代码语言:javascript
复制
@Service
public class MqServiceImpl implements MqService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private JmsTemplate jmsTemplate;

    @Autowired
    private MQDestination destination;

    @Handler
    @Override
    public void sendMessage(String textMessage) {
        logger.info("textMessage {} ", textMessage);
        logger.info("destination {}  ", destination);
        jmsTemplate.convertAndSend(destination, textMessage);
    }

}

然而,当我尝试启动应用程序时,我得到的是MQDestination' that could not be found.

代码语言:javascript
复制
service.impl.MqServiceImpl required a bean of type 'com.ibm.mq.jms.MQDestination' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.ibm.mq.jms.MQDestination' in your configuration.

难道spring不应该打电话给DestinationResolver吗?

如果不是,如何为IBM注册目的地?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-08 07:28:22

您正在定义一个DestinationResolver bean,但是注入了一个MQDestination bean。这就是为什么你会犯这个错误。您应该注入DestinationResolver并在JmsTemplate上调用setDestinationResolver

但是JmsTemplate动态地解析目的地。这也适用于:

代码语言:javascript
复制
public void sendMessage(String textMessage) {
    String destination = "MY.QUEUE";
    jmsTemplate.convertAndSend(destination, textMessage);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55567335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档