mick
Connecting to Azure Service Bus with rabbitmq-amqp1.0-client
Has anyone had any success connecting to Azure Service Bus with rabbitmq-amqp1.0-client? I’m trying with:
conf = %{
address: "[namespace].servicebus.windows.net",
container_id: "test_container",
port: 5672,
sasl: {:plain, "[keyname]", "[keyvalue"}
}
:amqp10_client.open_connection conf
but keep getting:
{:error, {:shutdown, {:failed_to_start_child, :reader, :badarg}}}
I’ve also tried with an additional tls_opts: {5671} but get the same result.
Mick
Most Liked
shankardevy
@mick if you are still after this, you could try this code. It works for me:
conf = %{
:container_id => <<"test-container">>,
:address => 'abc-shankardevy.servicebus.windows.net',
:port => 5671,
:hostname => <<"abc-shankardevy.servicebus.windows.net">>,
:tls_opts => {:secure_port,[]},
:sasl =>
{:plain,<<"QUEUENAME">>,
<<"keykey">>},
:transfer_limit_margin => 100
}
{:ok, conn} = :amqp10_client.open_connection(conf)
{:ok, session} = :amqp10_client.begin_session(conn)
{:ok, sender } = :amqp10_client.attach_sender_link(session, "test-sender", "command")
out_msg = :amqp10_msg.new("my-tag", "my-body", false)
ok = :amqp10_client.send_msg(sender, out_msg)
slashmili
There has been some improvements, rabbitmq team has pushed amqp10_client to hex. it’s easier to include it to your project.
if you are given a connection string like:
Endpoint=sb://[namespace].servicebus.windows.net/;SharedAccessKeyName=MyKeyName;SharedAccessKey=MyAccessKey;EntityPath=MyEntityPath
Then you can use it in your project like
address = '[namespace].servicebus.windows.net'
hostname = to_string(address)
user = "MyKeyName"
password = "MyAccessKey"
port = 5671
queue_name = "MyEntityPath"
subscription_name = "MySubscriptionName" # This is not provided in the connection string but is an important value. With an invalid setting, you'll get "The messaging entity '....' could not be found.
opn_conf = %{
address: address,
hostname: hostname,
port: port,
container_id: subscription_name,
sasl: {:plain, user, password},
tls_opts: {:secure_port, []},
transfer_limit_margin: 100
}
{:ok, connection} = :amqp10_client.open_connection(opn_conf)
{:ok, session} = :amqp10_client.begin_session(connection)
{:ok, receiver} =
:amqp10_client.attach_receiver_link(
session,
subscription_name,
queue_name
)
:ok = :amqp10_client.flow_link_credit(receiver, 5, :never)
With this code snippet, the messages are sent to the caller’s process mailbox. For more advance usage checkout the source code
if you run it in iex, you can get the messages by running flush:
iex(1)> MyApp.run
iex(2)> flush
{:amqp10_event, {:connection, #PID<0.230.0>, :opened}}
{:amqp10_event, {:session, #PID<0.241.0>, :begun}}
{:amqp10_event, {:link, {:link_ref, :receiver, #PID<0.241.0>, 0}, :attached}}
slashmili
A shameless plug! We have built a Broadway Producer for AMQP1.0 which simplifies lots of low level details, if you are already a Broadway user, highly recommend to try it out.
slashmili
the SSL setting is part of what ssl module in erlang expect. It’s a bit cryptic but if you have it working once, you can reuse it ![]()
this is the settings for OTP 26: Erlang/OTP 26 Highlights - Erlang/OTP
If you are using older version this might come handy
ssl: [
verify: :verify_peer,
cacertfile: ~c"/etc/ssl/certs/ca-certificates.crt",
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
]
the crt files comes from ca-certificates package in Debian.
mmmrrr
Very nice! Thank you so much. I don’t know how this article slipped past me… When I deactivate the cert check with tls_opts: {:secure_port, [{:verify, :verify_none}]} it’s working - for testing this is currently enough.
Have you, by chance, ever used the managed identity authentication system in azure for the service bus? The pre-shared key variant is now working fine, but it doesn’t work with the oauth token one can get at the central identity management system.
I’ll whip up some documentation PRs for the off_broadway_amqp10 repo once I have understood and solved my issues if you’re interested ![]()







