void amqp::Sender::_addMetaToMessage(pn_message_t *pnmessage, IMessage const &message) { pn_timestamp_t utcTime; time(&utcTime); _addPropertiesToMessage(pnmessage, message); _addAnnotationsToMessage(pnmessage, message); pn_message_set_content_type(pnmessage, message.getContentType().c_str()); pn_message_set_inferred(pnmessage, true); pn_message_set_subject(pnmessage, message.getSubject().c_str()); pn_message_set_ttl(pnmessage, 86400000); pn_message_set_creation_time(pnmessage, utcTime); switch (message.getEncoding()) { case IMessage::UTF8: pn_message_set_content_encoding(pnmessage, "UTF-8"); break; case IMessage::UTF16: pn_message_set_content_encoding(pnmessage, "UTF-16"); break; } }
mama_status qpidBridgeMsgCodec_pack (msgBridge bridgeMessage, mamaMsg target, pn_message_t** protonMessage) { pn_data_t* properties = NULL; pn_data_t* body = NULL; mamaPayloadType payloadType = MAMA_PAYLOAD_UNKNOWN; const void* buffer = NULL; mama_size_t bufferLen = 0; char* subject = NULL; char* destination = NULL; char* inboxName = NULL; char* replyTo = NULL; char* targetSubject = NULL; mama_status status = MAMA_STATUS_OK; qpidMsgType type = QPID_MSG_PUB_SUB; if (NULL == bridgeMessage || NULL == target) { return MAMA_STATUS_NULL_ARG; } /* Get the underlying payload type */ mamaMsg_getPayloadType (target, &payloadType); /* If this is a qpid payload, we don't need to serialize */ if (MAMA_PAYLOAD_QPID == payloadType) { /* This will extract only the underlying handle */ mamaMsgImpl_getPayloadBuffer (target, &buffer, &bufferLen); /* Don't use function's proton message - use the one just extracted */ *protonMessage = (pn_message_t*) buffer; } else { const void* buffer = NULL; mama_size_t bufferLen = 0; /* This will extract a serialized version of the payload */ mamaMsg_getByteBuffer (target, &buffer, &bufferLen); /* Use the function's proton message if this is not a qpid payload */ body = pn_message_body (*protonMessage); pn_data_put_binary (body, pn_bytes(bufferLen, (char*)buffer)); } /* Set the subject for the middleware according to the bridge msg */ status = qpidBridgeMamaMsgImpl_getSendSubject (bridgeMessage, &subject); if (MAMA_STATUS_OK != status) { return status; } pn_message_set_subject (*protonMessage, subject); /* Set the URL destination for the middleware according to the bridge msg */ status = qpidBridgeMamaMsgImpl_getDestination (bridgeMessage, &destination); if (MAMA_STATUS_OK != status) { return status; } pn_message_set_address (*protonMessage, destination); /* Get the properties from the message */ properties = pn_message_properties (*protonMessage); /* Ensure position is at the start */ pn_data_rewind (properties); /* Main container for meta data should be a list to allow expansion */ pn_data_put_list (properties); /* Enter into the list for access to its elements */ pn_data_enter (properties); /* Set the message type for the middleware according to the bridge msg */ status = qpidBridgeMamaMsgImpl_getMsgType (bridgeMessage, &type); if (MAMA_STATUS_OK != status) { return status; } pn_data_put_ubyte (properties, type); switch (type) { /* For inbox requests, set inbox name and reply to URLs */ case QPID_MSG_INBOX_REQUEST: status = qpidBridgeMamaMsgImpl_getInboxName (bridgeMessage, &inboxName); if (MAMA_STATUS_OK != status) { return status; } pn_data_put_string (properties, pn_bytes (strlen(inboxName), inboxName)); status = qpidBridgeMamaMsgImpl_getReplyTo (bridgeMessage, &replyTo); if (MAMA_STATUS_OK != status) { return status; } pn_data_put_string (properties, pn_bytes (strlen(replyTo), replyTo)); break; /* For inbox responses, set the target subject (e.g. initial for XX) */ case QPID_MSG_INBOX_RESPONSE: status = qpidBridgeMamaMsgImpl_getTargetSubject (bridgeMessage, &targetSubject); if (MAMA_STATUS_OK != status) { return status; } pn_data_put_string (properties, pn_bytes (strlen(targetSubject), targetSubject)); break; /* The following message types require no further meta data */ case QPID_MSG_TERMINATE: case QPID_MSG_SUB_REQUEST: case QPID_MSG_PUB_SUB: default: break; } /* Exit out of the list previously entered */ pn_data_exit (properties); return MAMA_STATUS_OK; }
void message::subject(const std::string &s) { check(pn_message_set_subject(pn_msg(), s.c_str())); }