哪些API可用于连接到IBM websphere MQ

时间:2015-04-07 12:44:20

标签: ibm-mq

我有一个要求,我需要使用IBM websphere消息队列pub子功能。 基本上我必须写订户部分。 我需要知道我可以用什么编程语言来编写除java以外的API。 我可以使用perl / shell / python编写它吗?

4 个答案:

答案 0 :(得分:3)

Python爱好者可以使用PyMQI。但请注意,这个产品是来自IBM的 NOT

答案 1 :(得分:1)

使用MQ Client API。它包括像这样的C ++样本:

int main ( int argc, char * * argv ) {
  ImqQueueManager mgr;             // Queue manager
  ImqQueue queue;                  // Queue
  ImqMessage msg;                  // Data message
  ImqGetMessageOptions gmo;        // Get message options
  char buffer[ 101 ];              // Message buffer
  ImqChannel * pchannel = 0 ;      // Channel definition

  printf( "Sample IMQSGET start\n" );
  if ( argc < 2 ) {
    printf( "Required parameter missing - queue name\n" );
    exit( 99 );
  }

  // Create object descriptor for subject queue
  queue.setName( argv[ 1 ] );
  if ( argc > 2 ) {
    mgr.setName( argv[ 2 ] );
  }

  // Define a channel for client communication.
  if ( argc > 3 ) {
    ImqString strParse( argv[ 3 ] );
    ImqString strToken ;

    pchannel = new ImqChannel ;
    pchannel -> setHeartBeatInterval( 1 );

    // Break down the channel definition,
    // which is of the form "channel-name/transport-type/connection-name".
    if ( strParse.cutOut( strToken, '/' ) ) {
      pchannel -> setChannelName( strToken );

      if ( strParse.cutOut( strToken, '/' ) ) {

        // Interpret the transport type.
        if ( strToken.upperCase( ) == (ImqString)"LU62" ) {
          pchannel -> setTransportType( MQXPT_LU62 );
        }
        if ( strToken.upperCase( ) == (ImqString)"NETBIOS" ) {
          pchannel -> setTransportType( MQXPT_NETBIOS );
        }
        if ( strToken.upperCase( ) == (ImqString)"SPX" ) {
          pchannel -> setTransportType( MQXPT_SPX );
        }
        if ( strToken.upperCase( ) == (ImqString)"TCP" ) {
          pchannel -> setTransportType( MQXPT_TCP );
        }

        // Establish the connection name.
        if ( strParse.cutOut( strToken ) ) {
          pchannel -> setConnectionName( strToken );
        }
      }
    }

    mgr.setChannelReference( pchannel );
  }

  // Connect to queue manager
  if ( ! mgr.connect( ) ) {

    /* stop if it failed     */
    printf( "ImqQueueManager::connect failed with reason code %ld\n",
            (long)mgr.reasonCode( ) );
    exit( (int)mgr.reasonCode( ) );
  }

  // Associate queue with queue manager.
  queue.setConnectionReference( mgr );

  // Open the named message queue for input; exclusive or shared
  // use of the queue is controlled by the queue definition here
  queue.setOpenOptions(
                   MQOO_INPUT_AS_Q_DEF /* open queue for input      */
                 + MQOO_FAIL_IF_QUIESCING
                             );        /* but not if MQM stopping   */
  queue.open( );

  /* report reason, if any; stop if failed      */
  if ( queue.reasonCode( ) ) {
    printf( "ImqQueue::open ended with reason code %ld\n",
            (long)queue.reasonCode( ) );
  }

  if ( queue.completionCode( ) == MQCC_FAILED ) {
    printf( "unable to open queue for input\n" );
  }

  // Get messages from the message queue
  // Loop until there is a failure
  msg.useEmptyBuffer( buffer, sizeof( buffer ) - 1 );
                                 /* buffer size available for GET   */
  gmo.setOptions( MQGMO_WAIT |   /* wait for new messages           */
                  MQGMO_FAIL_IF_QUIESCING );
  gmo.setWaitInterval( 15000 );  /* 15 second limit for waiting     */

  while ( queue.completionCode( ) != MQCC_FAILED ) {

    // In order to read the messages in sequence, MsgId and
    // CorrelID must have the default value.  MQGET sets them
    // to the values in for message it returns, so re-initialise
    // them before every call
    msg.setMessageId( );
    msg.setCorrelationId( );

    if ( queue.get( msg, gmo ) ) {

      // Display each message received
      if ( msg.formatIs( MQFMT_STRING ) ) {

        buffer[ msg.dataLength( ) ] = 0 ;  /* add terminator          */
        printf( "message <%s>\n", msg.bufferPointer( ) );

      } else {
        printf( "Non-text message\n" );
      }

    } else {

      /* report reason, if any     */
      if ( queue.reasonCode( ) == MQRC_NO_MSG_AVAILABLE ) {
                                /* special report for normal end    */
        printf( "no more messages\n" );
      } else {
                                /* general report for other reasons */
        printf( "ImqQueue::get ended with reason code %ld\n",
                (long)queue.reasonCode( ) );

        /*   treat truncated message as a failure for this sample   */
        if ( queue.reasonCode( ) == MQRC_TRUNCATED_MSG_FAILED ) {
          break ;
        }
      }
    }

  }

  // Close the source queue (if it was opened)
  if ( ! queue.close( ) ) {

    /* report reason, if any     */
    printf( "ImqQueue::close failed with reason code %ld\n",
            (long)queue.reasonCode( ) );
  }

  // Disconnect from MQM if not already connected (the
  // ImqQueueManager object handles this situation automatically)
  if ( ! mgr.disconnect( ) ) {

    /* report reason, if any     */
    printf( "ImqQueueManager::disconnect failed with reason code %ld\n",
            (long)mgr.reasonCode( ) );
  }

  // Tidy up the channel object if allocated.
  if ( pchannel ) {
    mgr.setChannelReference( );
    delete pchannel ;
  }

  printf( "Sample IMQSGET end\n" );
  return( 0 );
}

答案 2 :(得分:0)

IBM为以下语言提供MQ客户端:

C,C ++ ,. NET,Java

答案 3 :(得分:0)

WebSphere MQ提供对以下编程过程语言的支持: C Visual Basic(仅限Windows系统) COBOL 汇编语言(仅限WebSphere MQ for z /OS®) RPG(仅适用于IBM®i的WebSphere MQ) PL / I(仅限WebSphere MQ for z / OS)

这些语言使用消息队列接口(MQI)来访问消息队列服务。

WebSphere MQ提供以下支持: 。净 的ActiveX C ++ Java的 JMS

这些语言使用WebSphere MQ对象模型,该模型提供的类提供与WebSphere MQ调用和结构相同的功能。

Fuente

相关问题