-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathsend.jl
executable file
·24 lines (21 loc) · 942 Bytes
/
send.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using AMQPClient
const VIRTUALHOST ="/"
const HOST = "127.0.0.1"
function send(message)
# 1. Create a connection to the localhost or 127.0.0.1 of virtualhost '/'
connection(; virtualhost=VIRTUALHOST, host=HOST) do conn
# 2. Create a channel to send messages
channel(conn, AMQPClient.UNUSED_CHANNEL, true) do chan
# 3. Declare a queue
success, queue_name, message_count, consumer_count = queue_declare(chan, "hello")
# 4.1 Create a message, AMQPCleint only accepts message in UInt8
data = convert(Vector{UInt8}, codeunits(message))
msg = Message(data, content_type="text/plain", delivery_mode=PERSISTENT)
# 4.2 Send a message
basic_publish(chan, msg; exchange="", routing_key="hello")
println("Message sent: $message")
# 5. Auto-closes the channel and connection
end
end
end
send("Hello World!")