Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
europa-erp-python
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fa0ac3f1
authored
Sep 14, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add rabbit_mq
parent
479e5c0c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
utils/rabbit_mq.py
utils/rabbit_mq.py
0 → 100644
View file @
fa0ac3f1
import
pika
class
Producer
:
def
__init__
(
self
,
user
=
""
,
password
=
""
,
host
=
"localhost"
,
port
=
5672
,
queue_name
=
""
,
durable
=
True
,
exchange
=
None
,
routing_key
=
None
,
):
credentials
=
pika
.
PlainCredentials
(
username
=
user
,
password
=
password
)
self
.
conn
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
host
,
port
=
port
,
credentials
=
credentials
))
channel
=
self
.
conn
.
channel
()
channel
.
queue_declare
(
queue
=
queue_name
,
durable
=
durable
)
self
.
channel
=
channel
def
push
(
self
,
message
,
exchange
=
None
,
routing_key
=
None
):
if
exchange
is
None
or
routing_key
is
None
:
self
.
channel
.
basic_publish
(
exchange
=
""
,
routing_key
=
""
,
body
=
str
.
encode
(
message
))
self
.
channel
.
basic_publish
(
exchange
=
exchange
,
routing_key
=
routing_key
,
body
=
str
.
encode
(
message
))
def
close
(
self
):
try
:
self
.
channel
.
close
()
self
.
conn
.
close
()
except
Exception
as
e
:
print
(
e
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment