Skip to content

Поддержка виртуальных хостов в строке подключения RabbitMQ #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/receiver/storage/store/rabbitmq/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *Connector) Init(cfg map[string]string) error {
}

c.config = cfg
conStr := fmt.Sprintf("amqp://%s:%s@%s:%s/", c.config["user"], c.config["password"], c.config["host"], c.config["port"])
conStr := fmt.Sprintf("amqp://%s:%s@%s:%s/%s", c.config["user"], c.config["password"], c.config["host"], c.config["port"], c.config["virtual_host"])
if c.connection, err = amqp.Dial(conStr); err != nil {
return fmt.Errorf("Ошибка установки соединеия RabbitMQ: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions configs/receiver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ storage:
# user: "guest"
# password: "guest"
# exchange: "receiver"
# virtual_host: ""
# nats:
# plugin: "nats.so"
# servers: "nats://localhost:1222, nats://localhost:1223, nats://localhost:1224"
Expand Down
42 changes: 42 additions & 0 deletions tools/rabbit_monitor.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не очень понятно для чего этот монитор, не плохо бы добавить какой-нибудь комментарий в заголовок

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import yaml
import argparse
import asyncio
import aio_pika
import aio_pika.abc
import json
from pprint import pprint

async def main(conStr, exchange, routing_key):
connection = await aio_pika.connect_robust(
conStr
)
async with connection:
channel: aio_pika.abc.AbstractChannel = await connection.channel()
queue: aio_pika.abc.AbstractQueue = await channel.declare_queue(auto_delete=True)
exchange = await channel.declare_exchange(exchange)
await queue.bind(exchange, routing_key)
async with queue.iterator() as queue_iter:
async for message in queue_iter:
async with message.process():
data = json.loads(message.body)
pprint(data)
print('\n\n')




if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", help="Конфигурационный файл", type=str)


args = parser.parse_args()

with open(args.config) as f:
c = yaml.safe_load(f)
config = c['storage']['rabbitmq']

conStr = "amqp://%s:%s@%s:%s/%s" % (config["user"], config["password"], config["host"], config["port"], config["virtual_host"])


asyncio.run(main(conStr, config["exchange"], config["key"]))