/* Send reply to inbox. */ mama_status qpidBridgeMamaPublisher_sendReplyToInbox (publisherBridge publisher, void* request, mamaMsg reply) { qpidPublisherBridge* impl = (qpidPublisherBridge*) publisher; mamaMsg requestMsg = (mamaMsg) request; const char* inboxSubject = NULL; const char* replyTo = NULL; msgBridge bridgeMsg = NULL; mama_status status = MAMA_STATUS_OK; if (NULL == publisher || NULL == request || NULL == reply) { return MAMA_STATUS_NULL_ARG; } /* Set properties for the outgoing bridge message */ qpidBridgeMamaMsgImpl_setMsgType (impl->mMamaBridgeMsg, QPID_MSG_INBOX_RESPONSE); /* Target is for MD subscriptions to respond to this particular topic */ qpidBridgeMamaMsgImpl_setTargetSubject (impl->mMamaBridgeMsg, impl->mSubject); /* Get the incoming bridge message from the mamaMsg */ status = mamaMsgImpl_getBridgeMsg (requestMsg, &bridgeMsg); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaPublisher_sendReplyToInbox(): " "Could not get bridge message from cached" " queue mamaMsg [%s]", mamaStatus_stringForStatus (status)); return status; } /* Get properties from the incoming bridge message */ status = qpidBridgeMamaMsgImpl_getInboxName (bridgeMsg, (char**) &inboxSubject); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaPublisher_sendReplyToInbox(): " "Could not get inbox name [%s]", mamaStatus_stringForStatus (status)); return status; } status = qpidBridgeMamaMsgImpl_getReplyTo (bridgeMsg, (char**) &replyTo); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaPublisher_sendReplyToInbox(): " "Could not get reply to [%s]", mamaStatus_stringForStatus (status)); return status; } if (NULL == inboxSubject) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaPublisher_sendReplyToInbox(): " "No reply address specified - cannot respond to inbox %s.", inboxSubject); return status; } /* Set the send subject to publish onto the inbox subject */ status = qpidBridgeMamaMsg_setSendSubject (impl->mMamaBridgeMsg, inboxSubject, impl->mSource); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaPublisher_sendReplyToInbox(): " "Could not set send subject '%s' [%s]", inboxSubject, mamaStatus_stringForStatus (status)); return status; } /* Set the destination to the replyTo URL */ status = qpidBridgeMamaMsgImpl_setDestination (impl->mMamaBridgeMsg, replyTo); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "qpidBridgeMamaPublisher_sendReplyToInbox(): " "Could not set destination '%s' [%s]", replyTo, mamaStatus_stringForStatus (status)); return status; } /* Fire out the message to the inbox */ return qpidBridgeMamaPublisher_send (publisher, reply); }
/** * Called when message removed from queue by dispatch thread * * @param data The Avis Attributes* clone (must be freed) * @param closure The subscriber */ static void MAMACALLTYPE avis_queue_callback (void* data, void* closure) { mama_status status; mamaMsg tmpMsg; msgBridge bridgeMsg; /* cant do anything without a subscriber */ if (!avisSub(closure)) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!"); return; } /*Make sure that the subscription is processing messages*/ if ((!avisSub(closure)->mIsNotMuted) || (!avisSub(closure)->mIsValid)) return; /*This is the reuseable message stored on the associated MamaQueue*/ tmpMsg = mamaQueueImpl_getMsg(avisSub(closure)->mQueue); if (!tmpMsg) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not get cached mamaMsg from event queue."); return; } /*Get the bridge message from the mamaMsg*/ if (MAMA_STATUS_OK!=(status=mamaMsgImpl_getBridgeMsg (tmpMsg, &bridgeMsg))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not get bridge message from cached" " queue mamaMsg [%d]", status); return; } /*Set the buffer and the reply handle on the bridge message structure*/ avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0); if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMsgBuffer (tmpMsg, data, 0, MAMA_PAYLOAD_AVIS))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): mamaMsgImpl_setMsgBuffer() failed. [%d]", status); return; } /*Process the message as normal*/ if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg (avisSub(closure)->mMamaSubscription, tmpMsg))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "mamaSubscription_processMsg() failed. [%d]", status); } attributes_free ((Attributes*)data); free ((Attributes*)data); }
/** * Called when message removed from queue by dispatch thread * * @param data The Avis Attributes* clone (must be freed) * @param closure The subscriber */ static void MAMACALLTYPE avis_queue_callback (mamaQueue queue, void* closure) { mama_status status = MAMA_STATUS_OK; mamaMsg tmpMsg = NULL; msgBridge bridgeMsg = NULL; const void* buf = NULL; mama_size_t bufSize = 0; avisCallbackContext* ctx = (avisCallbackContext*) closure; void* data = ctx->attributes; void* subscriber = ctx->subscriber; /* cant do anything without a subscriber */ if (!subscriber) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): called with NULL subscriber!"); attributes_destroy (data); free (ctx); return; } /*Make sure that the subscription is processing messages*/ if ((!avisSub(subscriber)->mIsNotMuted) || (!avisSub(subscriber)->mIsValid)) { attributes_destroy (data); free (ctx); return; } /*This is the reuseable message stored on the associated MamaQueue*/ tmpMsg = mamaQueueImpl_getMsg(avisSub(subscriber)->mQueue); if (!tmpMsg) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not get cached mamaMsg from event queue."); attributes_destroy (data); free (ctx); return; } /*Get the bridge message from the mamaMsg*/ if (MAMA_STATUS_OK!=(status=mamaMsgImpl_getBridgeMsg (tmpMsg, &bridgeMsg))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not get bridge message from cached" " queue mamaMsg [%d]", status); attributes_destroy (data); free (ctx); return; } /*Set the buffer and the reply handle on the bridge message structure*/ if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMsgBuffer (tmpMsg, data, 0, MAMA_PAYLOAD_AVIS))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): mamaMsgImpl_setMsgBuffer() failed. [%d]", status); attributes_destroy (data); free (ctx); return; } if (MAMA_STATUS_OK == mamaMsg_getOpaque ( tmpMsg, ENCLOSED_MSG_FIELD_NAME, 0, &buf, &bufSize) && bufSize > 0) { mamaMsg encMsg = NULL; mamaBridgeImpl* bridge = mamaSubscription_getBridgeImpl (avisSub(subscriber)->mMamaSubscription); status = mamaMsg_createFromByteBuffer (&encMsg, buf, bufSize); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "Could not create message from enclosed byte buffer. [%d]", status); attributes_destroy (data); free (ctx); return; } mamaMsgImpl_useBridgePayload (encMsg, bridge); mamaMsgImpl_getBridgeMsg (encMsg, &bridgeMsg); /*Set the buffer and the reply handle on the bridge message structure*/ avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0); if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST) { mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): " "Received enclosed message: %s", mamaMsg_toString (encMsg)); } if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg (avisSub(subscriber)->mMamaSubscription, encMsg))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "mamaSubscription_processMsg() failed. [%d]", status); } mamaMsg_destroy (encMsg); } else { avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0); if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST) { mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): " "Received message: %s", mamaMsg_toString (tmpMsg)); } /*Process the message as normal*/ if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg (avisSub(subscriber)->mMamaSubscription, tmpMsg))) { mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): " "mamaSubscription_processMsg() failed. [%d]", status); } } free (ctx); }