forked from akalend/amqpcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMQPMessage.cpp
147 lines (120 loc) · 3.13 KB
/
AMQPMessage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* AMQPMessage.cpp
* librabbitmq++
*
* Created by Alexandre Kalendarev on 15.04.10.
*
*/
#include "AMQPcpp.h"
using namespace std;
AMQPMessage::AMQPMessage( AMQPQueue * queue ) {
this->queue=queue;
message_count=-1;
data=NULL;
}
AMQPMessage::~AMQPMessage() {
if (data) {
free(data);
}
}
void AMQPMessage::setMessage(const char * data,uint32_t length) {
if (!data)
return;
if (this->data)
free(this->data);
this->data = (char*)malloc(length + 1);
if (!this->data) {
throw AMQPException("setMessage: malloc failed");
}
memcpy(this->data,data,length);
this->data[length] = '\0';
this->len = length;
}
char * AMQPMessage::getMessage(uint32_t* length) {
if (this->data)
{
*length = this->len;
return this->data;
}
*length = 0;
return '\0';
}
string AMQPMessage::getConsumerTag() {
return this->consumer_tag;
}
void AMQPMessage::setConsumerTag(amqp_bytes_t consumer_tag) {
this->consumer_tag.assign( (char*)consumer_tag.bytes, consumer_tag.len );
}
void AMQPMessage::setConsumerTag(string consumer_tag) {
this->consumer_tag=consumer_tag;
}
void AMQPMessage::setDeliveryTag(uint32_t delivery_tag) {
this->delivery_tag=delivery_tag;
}
uint32_t AMQPMessage::getDeliveryTag() {
return this->delivery_tag;
}
void AMQPMessage::setMessageCount(int count) {
this->message_count = count;
}
int AMQPMessage::getMessageCount() {
return message_count;
}
void AMQPMessage::setExchange(amqp_bytes_t exchange) {
if (exchange.len)
this->exchange.assign( (char*)exchange.bytes, exchange.len );
}
void AMQPMessage::setExchange(string exchange) {
this->exchange = exchange;
}
string AMQPMessage::getExchange() {
return exchange;
}
void AMQPMessage::setRoutingKey(amqp_bytes_t routing_key) {
if (routing_key.len)
this->routing_key.assign( (char*)routing_key.bytes, routing_key.len );
}
void AMQPMessage::setRoutingKey(string routing_key) {
this->routing_key=routing_key;
}
string AMQPMessage::getRoutingKey() {
return routing_key;
}
void AMQPMessage::addHeader(string name, amqp_bytes_t * value) {
string svalue;
svalue.assign(( const char *) value->bytes, value->len);
headers[name] = svalue;
//headers.insert( pair<string,string>(name,svalue));
}
void AMQPMessage::addHeader(string name, uint64_t * value) {
char ivalue[32];
memset(ivalue,0,32);
sprintf(ivalue,"%lu", *value);
headers[name] = string(ivalue);
//headers.insert(pair<string,string>(name,string(ivalue)));
}
void AMQPMessage::addHeader(string name, uint8_t * value) {
char ivalue[4];
memset(ivalue,0,4);
sprintf(ivalue,"%d",*value);
headers[name] = string(ivalue);
//headers.insert( pair<string,string>(name,string(ivalue)));
}
void AMQPMessage::addHeader(amqp_bytes_t * name, amqp_bytes_t * value) {
//cout << "name " << name << endl;
string sname;
sname.assign((const char *) name->bytes, name->len);
string svalue;
svalue.assign((const char *) value->bytes, value->len);
headers[sname] = string(svalue);
//headers.insert(pair<string, string>(sname, svalue));
}
string AMQPMessage::getHeader(string name) {
if (headers.find(name) == headers.end())
return "";
else
return headers[name];
}
AMQPQueue * AMQPMessage::getQueue() {
return queue;
}