FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rabbitmq-tutorials/cpp/receive.cpp at main · rabbitmq/rabbitmq-tutorials · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
rabbitmq
/
rabbitmq-tutorials
Public
Notifications
You must be signed in to change notification settings
Fork
3.5k
Star
6.9k
Code
Issues
3
Pull requests
1
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
rabbitmq-tutorials
/
cpp
/
receive.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (57 loc) · 2.18 KB
Breadcrumbs
rabbitmq-tutorials
/
cpp
/
receive.cpp
Copy path
File metadata and controls
68 lines (57 loc) · 2.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
Tutorial 1: "Hello World!" consumer
//
//
Consumes messages from the `hello` queue and prints them.
#
include
<
rmqa_consumer.h
>
#
include
<
rmqa_rabbitcontext.h
>
#
include
<
rmqa_topology.h
>
#
include
<
rmqa_vhost.h
>
#
include
<
rmqp_messageguard.h
>
#
include
<
rmqt_consumerconfig.h
>
#
include
<
rmqt_fieldvalue.h
>
#
include
<
rmqt_message.h
>
#
include
<
rmqt_plaincredentials.h
>
#
include
<
rmqt_result.h
>
#
include
<
rmqt_simpleendpoint.h
>
#
include
<
bslmt_semaphore.h
>
#
include
<
bsl_memory.h
>
#
include
<
bsl_string.h
>
#
include
<
iostream
>
#
include
<
string
>
using
namespace
BloombergLP
;
int
main
()
{
rmqa::RabbitContext rabbit;
bsl::shared_ptr<rmqa::VHost> vhost = rabbit.
createVHostConnection
(
"
tutorial-one consumer
"
,
bsl::make_shared<rmqt::SimpleEndpoint>(
"
localhost
"
,
"
/
"
),
bsl::make_shared<rmqt::PlainCredentials>(
"
guest
"
,
"
guest
"
));
rmqa::Topology topology;
rmqt::FieldTable quorum;
quorum[
"
x-queue-type
"
] =
rmqt::FieldValue
(
bsl::string
(
"
quorum
"
));
rmqt::QueueHandle queue =
topology.
addQueue
(
"
hello
"
, rmqt::AutoDelete::
OFF
, rmqt::Durable::
ON
, quorum);
//
Each delivery is passed to this callback on a background thread. rmqcpp
//
does not auto-acknowledge: acking only once the message is handled means
//
an interrupted consumer leaves the message on the queue for redelivery.
rmqt::Result<rmqa::Consumer> consumerResult = vhost->
createConsumer
(
topology,
queue,
[](rmqp::MessageGuard& guard) {
const
rmqt::Message& message = guard.
message
();
std::string
body
(
reinterpret_cast
<
const
char
*>(message.
payload
()),
message.
payloadSize
());
std::cout <<
"
[x] Received
"
<< body << std::endl;
guard.
ack
();
},
rmqt::ConsumerConfig
().
setConsumerTag
(
"
tutorial-one consumer
"
));
if
(!consumerResult) {
std::cerr <<
"
Failed to create consumer:
"
<< consumerResult.
error
()
<<
"
\n
"
;
return
1
;
}
std::cout <<
"
[*] Waiting for messages. To exit press CTRL+C
"
<< std::endl;
//
The consumer runs on background threads, so park the main thread here.
bslmt::Semaphore stop;
stop.
wait
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL