forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemit_log_direct.exs
More file actions
28 lines (23 loc) · 759 Bytes
/
emit_log_direct.exs
File metadata and controls
28 lines (23 loc) · 759 Bytes
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
{:ok, connection} = AMQP.Connection.open
{:ok, channel} = AMQP.Channel.open(connection)
{severities, raw_message, _} =
System.argv
|> OptionParser.parse(strict: [info: :boolean,
warning: :boolean,
error: :boolean])
|> case do
{[], msg, _} -> {[info: true], msg, []}
other -> other
end
message =
case raw_message do
[] -> "Hello World!"
words -> Enum.join(words, " ")
end
AMQP.Exchange.declare(channel, "direct_logs", :direct)
for {severity, true} <- severities do
severity = severity |> to_string
AMQP.Basic.publish(channel, "direct_logs", severity, message)
IO.puts " [x] Sent '[#{severity}] #{message}'"
end
AMQP.Connection.close(connection)