-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
511 changed files
with
4,833 additions
and
3,312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.PHONY:all | ||
all:publish_client consume_client | ||
CFLAG= -I../third/muduo/include/ | ||
LFALG= -L../third/muduo/lib -lgtest -lsqlite3 -lprotobuf -pthread -lmuduo_net -lmuduo_base -lz | ||
publish_client:publish_client.cc ../common/msg.pb.cc ../common/protocol.pb.cc ../third/muduo/include/muduo/protobuf/codec.cc | ||
g++ -g $(CFLAG) $^ -o $@ -std=c++17 $(LFALG) | ||
|
||
consume_client:consume_client.cc ../common/msg.pb.cc ../common/protocol.pb.cc ../third/muduo/include/muduo/protobuf/codec.cc | ||
g++ -g $(CFLAG) $^ -o $@ -std=c++17 $(LFALG) | ||
|
||
.PHONY:clean | ||
clean: | ||
rm publish_client consume_client -rf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "connection.hpp" | ||
#include "../common/logger.hpp" | ||
|
||
void callBack(XuMQ::Channel::ptr &channel, const std::string &consumer_tag, const XuMQ::BasicProperties *bp, const std::string &body) | ||
{ | ||
info(XuMQ::logger, "消费者%s 消费的消息是:%s", consumer_tag.c_str(), body.c_str()); | ||
channel->basicAck(bp->id()); | ||
} | ||
int main(int argc, char *argv[]) | ||
{ | ||
if (argc != 2) | ||
{ | ||
info(XuMQ::logger, "usage: ./consume_client queue1"); | ||
} | ||
// 实例化异步工作线程对象 | ||
XuMQ::AsyncWorker::ptr awp = std::make_shared<XuMQ::AsyncWorker>(); | ||
// 实例化连接对象 | ||
XuMQ::Connection::ptr conn = std::make_shared<XuMQ::Connection>("127.0.0.1", 8888, awp); | ||
// 通过连接创建信道 | ||
XuMQ::Channel::ptr channel = conn->openChannel(); | ||
|
||
// 声明交换机exchange1 | ||
google::protobuf::Map<std::string, std::string> tmp; | ||
channel->declareExchange("exchange1", XuMQ::ExchangeType::TOPIC, true, false, tmp); | ||
// 声明队列queue1 | ||
channel->declareQueue("queue1", true, false, false, tmp); | ||
// 声明队列queue2 | ||
channel->declareQueue("queue2", true, false, false, tmp); | ||
// 绑定queue1-exchange1 设置binding_key = queue1 | ||
channel->queueBind("exchange1", "queue1", "queue1"); | ||
// 绑定queue2-exchange1 设置binding_key = news.music.# | ||
channel->queueBind("exchange1", "queue2", "news.music.#"); | ||
// 订阅指定队列消息 | ||
auto func = std::bind(callBack, channel, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); | ||
channel->basicConsume("consumer1", argv[1], false, func); | ||
while (true) | ||
{ | ||
std::this_thread::sleep_for(std::chrono::seconds(3)); | ||
} | ||
conn->closeChannel(channel); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "connection.hpp" | ||
int main() | ||
{ | ||
// 实例化异步工作线程对象 | ||
XuMQ::AsyncWorker::ptr awp = std::make_shared<XuMQ::AsyncWorker>(); | ||
// 实例化连接对象 | ||
XuMQ::Connection::ptr conn = std::make_shared<XuMQ::Connection>("127.0.0.1", 8888, awp); | ||
// 通过连接创建信道 | ||
XuMQ::Channel::ptr channel = conn->openChannel(); | ||
// 完成服务 | ||
// 声明交换机exchange1 | ||
google::protobuf::Map<std::string, std::string> tmp; | ||
channel->declareExchange("exchange1", XuMQ::ExchangeType::TOPIC, true, false, tmp); | ||
// 声明队列queue1 | ||
channel->declareQueue("queue1", true, false, false, tmp); | ||
// 声明队列queue2 | ||
channel->declareQueue("queue2", true, false, false, tmp); | ||
// 绑定queue1-exchange1 设置binding_key = queue1 | ||
channel->queueBind("exchange1", "queue1", "queue1"); | ||
// 绑定queue2-exchange1 设置binding_key = news.music.# | ||
channel->queueBind("exchange1", "queue2", "news.music.#"); | ||
// 发布消息 | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
XuMQ::BasicProperties bp; | ||
bp.set_id(XuMQ::UUIDHelper::uuid()); | ||
bp.set_delivery_mode(XuMQ::DeliveryMode::DURABLE); | ||
bp.set_routing_key("news.music.pop"); | ||
channel->basicPublish("exchange1", &bp, "hello-" + std::to_string(i)); | ||
} | ||
XuMQ::BasicProperties bp1; | ||
bp1.set_id(XuMQ::UUIDHelper::uuid()); | ||
bp1.set_delivery_mode(XuMQ::DeliveryMode::DURABLE); | ||
bp1.set_routing_key("news.music.sport"); | ||
channel->basicPublish("exchange1", &bp1, "hello XU"); | ||
XuMQ::BasicProperties bp2; | ||
bp2.set_id(XuMQ::UUIDHelper::uuid()); | ||
bp2.set_delivery_mode(XuMQ::DeliveryMode::DURABLE); | ||
bp2.set_routing_key("news.sport"); | ||
channel->basicPublish("exchange1", &bp2, "hello ???"); | ||
// 关闭信道 | ||
conn->closeChannel(channel); | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.