mick

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

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

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

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

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 :grimacing:

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

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 :slight_smile:

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement