FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rabbitmqexample/messagging/client_python/simul.py at master · NIVJAIN/rabbitmqexample · GitHub
NIVJAIN
/
rabbitmqexample
Public
forked from
Gsantomaggio/rabbitmqexample
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rabbitmqexample
/
messagging
/
client_python
/
simul.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (44 loc) · 1.68 KB
Breadcrumbs
rabbitmqexample
/
messagging
/
client_python
/
simul.py
Copy path
File metadata and controls
58 lines (44 loc) · 1.68 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
# /bin/python
import
pika
from
threading
import
Thread
import
os
import
sys
import
datetime
TEAM_EXCHANGE_NAME
=
"my_company"
ROOMS
=
[
"tech.programming"
,
"tech.networking"
,
"marketing"
]
def
publish_message
(
channel
,
routing_key
,
message
,
is_private
):
t
=
datetime
.
datetime
.
now
()
headers
=
{
'sender_user'
:
"simulation user"
,
'sent'
:
t
.
strftime
(
'%m/%d/%Y %H:%M:%S'
),
'is_private'
:
is_private
}
properties
=
pika
.
BasicProperties
(
headers
=
headers
,
delivery_mode
=
2
)
print
"sending.. "
+
message
channel
.
publish
(
exchange
=
TEAM_EXCHANGE_NAME
,
routing_key
=
routing_key
,
properties
=
properties
,
body
=
message
)
def
main
(
host
,
port
,
user
,
password
,
vhost
):
print
"Welcome to "
+
TEAM_EXCHANGE_NAME
+
" - Rooms: "
+
str
(
ROOMS
)
print
""
# setup rabbitmq connection
credentials
=
pika
.
PlainCredentials
(
user
,
password
)
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
,
port
,
vhost
,
credentials
))
channel
=
connection
.
channel
()
channel
.
exchange_declare
(
exchange
=
TEAM_EXCHANGE_NAME
,
exchange_type
=
"topic"
,
durable
=
True
)
for
i
in
range
(
1
,
10
):
publish_message
(
channel
,
"tech.programming"
,
"Simulation message n:"
+
str
(
i
),
False
)
def
kill
():
channel
.
stop_consuming
()
connection
.
add_timeout
(
0
,
kill
)
print
"Goodbye"
if
__name__
==
"__main__"
:
print
'Argument List:'
,
str
(
sys
.
argv
)
rabbitmq_host
=
sys
.
argv
[
1
];
rabbitmq_port
=
int
(
sys
.
argv
[
2
]);
rabbitmq_user
=
sys
.
argv
[
3
];
rabbitmq_password
=
sys
.
argv
[
4
];
rabbitmq_vhost
=
sys
.
argv
[
5
];
main
(
rabbitmq_host
,
rabbitmq_port
,
rabbitmq_user
,
rabbitmq_password
,
rabbitmq_vhost
)
Back
|
FazBrowse Home
|
New Git URL