MQ JMS Topic Equivalent in C/C++

自作多情 提交于 2020-03-24 02:38:07

问题


I don't have a clear knowledge about MQ using TOPICS and I have searched in IBM documentation and I can't find the way to subscribe with C++ to a Topic. In Java I have seen that you can go to the Websphere Control Panel and you configure it there. Programmatically how is possible to do it in C++? In C++ I have connected to queues using the functions MQCONN, MQOPEN and to get the messages I use MQGET and MQPUT, but I think I am only connected to queues not TOPICS. I want too to figure it out if I have the correct idea if connect to topic is different than connect to a queue. Thanks in advance guys.


回答1:


It is advisable to use the C MQ API when programming in C++ because the C++ classes are stabilized and have not (and will not) be updated with classes for topics, as per IBM Knowledge Center: Developing C++ applications

IBM WebSphere® MQ Version 7.0, enhancements to the IBM MQ programming interfaces are not applied to the C++ classes.

In order use a topic from the C MQ API here is a quick pseudo-code example. Please also check out the IBM supplied samples, such as amqspuba.c and amqssuba.c.

To Publish to a topic

MQOD mqod  {MQOD_DEFAULT};
MQCONN...
mqod.ObjectType = MQOT_TOPIC;
mqod.Version    = MQOD_VERSION_4; /* To use ObjectString field */
mqod.ObjectString.VSPtr = argv[1];
mqod.ObjectString.VSLength = MQVS_NULL_TERMINATED;
MQOPEN(hConn,
       &mqod,
       MQOO_OUTPUT,
       &hObj,
       &CompCode, &Reason);
MQPUT....

To Subscribe to a topic

MQSD mqsd  {MQSD_DEFAULT};
MQCONN...
mqsd.Options = MQSO_CREATE | MQSO_NON_DURABLE | MQSO_MANAGED;
mqsd.ObjectString.VSPtr = argv[1];
mqsd.ObjectString.VSLength = MQVS_NULL_TERMINATED;
MQSUB(hConn,
      &mqsd,
      &hObj,
      &hSub,
      &CompCode, &Reason);
MQGET from hObj...


来源:https://stackoverflow.com/questions/57101776/mq-jms-topic-equivalent-in-c-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!