예제 #1
0
mama_status
qpidBridgeMamaSubscription_create (subscriptionBridge* subscriber,
                                   const char*         source,
                                   const char*         symbol,
                                   mamaTransport       tport,
                                   mamaQueue           queue,
                                   mamaMsgCallbacks    callback,
                                   mamaSubscription    subscription,
                                   void*               closure)
{
    qpidSubscription*       impl        = NULL;
    qpidTransportBridge*    transport   = NULL;
    mama_status             status      = MAMA_STATUS_OK;
    pn_data_t*              data        = NULL;

    if ( NULL == subscriber || NULL == subscription || NULL == tport )
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                "qpidBridgeMamaSubscription_create(): something NULL");
        return MAMA_STATUS_NULL_ARG;
    }

    status = mamaTransport_getBridgeTransport (tport,
                                               (transportBridge*) &transport);

    if (MAMA_STATUS_OK != status || NULL == transport)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                "qpidBridgeMamaSubscription_create(): something NULL");
        return MAMA_STATUS_NULL_ARG;
    }

    /* Allocate memory for qpid subscription implementation */
    impl = (qpidSubscription*) calloc (1, sizeof (qpidSubscription));
    if (NULL == impl)
    {
        return MAMA_STATUS_NOMEM;
    }

    mamaQueue_getNativeHandle(queue, &impl->mQpidQueue);
    impl->mMamaCallback        = callback;
    impl->mMamaSubscription    = subscription;
    impl->mMamaQueue           = queue;
    impl->mTransport           = (mamaTransport)transport;
    impl->mSymbol              = symbol;
    impl->mClosure             = closure;
    impl->mIsNotMuted          = 1;
    impl->mIsTportDisconnected = 1;
    impl->mSubjectKey          = NULL;

    /* Use a standard centralized method to determine a topic key */
    qpidBridgeMamaSubscriptionImpl_generateSubjectKey (NULL,
                                                       source,
                                                       symbol,
                                                       &impl->mSubjectKey);

    /* Register the endpoint */
    endpointPool_registerWithoutIdentifier (transport->mSubEndpoints,
                                            impl->mSubjectKey,
                                            &impl->mEndpointIdentifier,
                                            impl);

    /* Notify the publisher that you have an interest in this topic */
    pn_message_clear        (transport->mMsg);

    /* Set the message meta data to reflect a subscription request */
    qpidBridgePublisherImpl_setMessageType (transport->mMsg,
                                            QPID_MSG_SUB_REQUEST);

    /* Set the outgoing address as provided by the transport configuration */
    pn_message_set_address  (transport->mMsg,
                             transport->mOutgoingAddress);

    /* Set the reply address */
    pn_message_set_reply_to (transport->mMsg,
                             transport->mReplyAddress);

    /* Get the proton message's body data for writing */
    data = pn_message_body  (transport->mMsg);

    /* Add in the subject key as the only string inside */
    pn_data_put_string      (data, pn_bytes (strlen (impl->mSubjectKey),
                                             impl->mSubjectKey));

    /* Send out the subscription registration of interest message */
    if (NULL != transport->mOutgoingAddress)
    {
        pn_messenger_put    (transport->mOutgoing, transport->mMsg);

        if (0 != PN_MESSENGER_SEND (transport->mOutgoing))
        {
            const char* qpid_error = PN_MESSENGER_ERROR (transport->mOutgoing);
            mama_log (MAMA_LOG_LEVEL_SEVERE,
                      "qpidBridgeMamaSubscription_create(): "
                      "pn_messenger_send Error:[%s]", qpid_error);
            return MAMA_STATUS_PLATFORM;
        }
    }

    mama_log (MAMA_LOG_LEVEL_FINEST,
              "qpidBridgeMamaSubscription_create(): "
              "created interest for %s.",
              impl->mSubjectKey);

    /* Mark this subscription as valid */
    impl->mIsValid = 1;

    *subscriber =  (subscriptionBridge) impl;

    return MAMA_STATUS_OK;
}
예제 #2
0
void message::clear() {
    if (pn_msg_) {
        impl().clear();
        pn_message_clear(pn_msg_);
    }
}