codebrane
codebrane

Reputation: 4650

Azure::ServiceBus subscription does not receive messages sent to topic via REST POST

Sending messages to Azure Service Bus topic using the Azure::ServiceBus ruby SDK works fine. The client is using a subscription and Azure::ServiceBus to receive the messages.

However, if the sender uses the ASB REST API to POST a message, the subscription has no messages. Only messages sent using Azure::ServiceBus appear in the subscription.

e.g this works fine for messages sent using Azure::ServiceBus but doesn't receive anything for messages sent using REST:

message = azure_service_bus_service.receive_subscription_message("testtopic", "retry-count-subscriber", { :peek_lock => true })

ASB returns 201 for POSTing so the messages are successfully sent to the topic.

Upvotes: 2

Views: 728

Answers (2)

suziki
suziki

Reputation: 14093

This can work fine on my side.

require 'net/http'
require 'net/https'
require 'uri'
require 'json'

uri = URI('https://yourservicebusnamespacename.servicebus.windows.net/yourservicebustopicname/messages')
bearertoken = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyIsImtpZCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyJ9.eyJhdWQiOiJodHRwczovL2Jvd21hbjEwMTIuc2VydmljZWJ1cy53aW5kb3dzLm5ldCIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0L2U0YzlhYjRlLWJkMjctNDBkNS04NDU5LTIzMGJhMmE3NTdmYi8iLCJpYXQiOjE2MTE3MzUwNTgsIm5iZiI6MTYxMTczNTA1OCwiZXhwIjoxNjExODE4MTU4LCJhaW8iOiJFMlpnWUtqc3RMKzRaZjRsM2xtVHQ4eU91UHJzQVFBPSIsImFwcGlkIjoiYjljNTdjOGQtMTkwNC00YjRiLWI2MjgtNDkxNzFiYzc4MzI0IiwiYXBwaWRhY3IiOiIxIiwiaWRwIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZTRjOWFiNGUtYmQyNy00MGQ1LTg0NTktMjMwYmEyYTc1N2ZiLyIsIm9pZCI6ImY5Y2ExOTI2LTBhOTUtNDQ1Yi04NDE5LTBjNGE2NGY5ZGM3NiIsInJoIjoiMC5BU2tBVHF2SjVDZTkxVUNFV1NNTG9xZFgtNDE4eGJrRUdVdEx0aWhKRnh2SGd5UXBBQUEuIiwic3ViIjoiZjljYTE5MjYtMGE5NS00NDViLTg0MTktMGM0YTY0ZjlkYzc2IiwidGlkIjoiZTRjOWFiNGUtYmQyNy00MGQ1LTg0NTktMjMwYmEyYTc1N2ZiIiwidXRpIjoiTGZLVXJRUzdtazZ3QUREdFFoZ29BQSIsInZlciI6IjEuMCJ9.GE_j9d1l6XlPrmx7q8bN-gJYKaP8DFf2JUErwPsa-Ca--UbkUJ-XGlmVbAq2oRY_Z-2zsVbLQVNA0soB1NZVwDcSk3I_cJdIVK8J0jx5Yh0AE3XdFnObDd8zo4lcupwQbEZQCGx_5L_iJU1cKZwHDMVmtKPvk2X8MhM2Ks6OOftT_2Wxz-lo79pc9K7L-XPbHpyjRdAfbYxLhifDKGX4XBpViAxZ7gFGULI1FILW7VvWZU02aUTkNOVf_csO3UJLNjmgcm-_nljq1tka6nQC4YiJKo3dMtlwOUoeJwxdFn1Mblvs6xdGsvIxGvxDwRSvy8n4ySUyrapOtgoGDMi82Q"
header = {'Content-Type': 'text/plain',
          'Authorization': bearertoken  
         }
mes = "This is testbowman message."
Net::HTTP.start(uri.host, uri.port,   
  :use_ssl => uri.scheme == 'https') do |http|
  request = Net::HTTP::Post.new(uri,header)
  request.body = mes

  response = http.request request # Net::HTTPResponse object 
  puts response.body
end 

puts 'Request is OK.'

And please don't forget to add the related add app to the RBAC role of azure service bus namespace:

enter image description here

Upvotes: 0

codebrane
codebrane

Reputation: 4650

The problem was caused by a SqlFilter on the subscriber:

retry_count > 9

The ruby post worked as it was setting it correctly:

message = Azure::ServiceBus::BrokeredMessage.new(message, { :retry_count => 10 })

changing :retry_count to anything less than 9 reproduced the problem in the ruby code too.

Upvotes: 1

Related Questions