How to send a message from Azure APIM to 2 different Service Bus Queues in 2 different Service Bus Namespaces

Malcolm K 156 Reputation points
2021-01-27T02:20:15.97+00:00

Hey

I am looking for any advice I can get please.

We have a scenario where we are pushing data from a system via an HTTPS call to Azure APIM and APIM is used to pass the message to a Service Bus Queue and then picked up by a LogicApp and Posted to an application API.

We want to run a series of parallel tests and we only have 1 source system and 2 target systems, so we want to push the data to our Production APIM and have arrive in both our Production and Test queues from the same single source message.

Anyone have any ideas on how to do this, or any advice.

Thanks
Malcolm

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,175 questions
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
635 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,211 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,536 Reputation points
    2021-01-28T05:39:43.083+00:00

    Hi @Malcolm K

    Thanks for the clarification.
    I believe you are calling service bus REST API to send the message to service bus queue. Please correct me if I am wrong.
    In this case, you can use sendrequest policy to make another REST API to send the same message to a different namespace.

    If you don't want to make any changes to the APIM then you can use topic (having two subscriptions) instead of the queue. The two subscriptions will have the same message copy. In one of the subscription, you configure the autoforwarding which will forward the message to the entity (topic/queue) of another namespace.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Malcolm K 156 Reputation points
    2021-02-05T01:59:37.7+00:00

    Hey

    I found a better solution for us so thought I would share for completeness.... I created a Azure Function App with a function that had an HTTP Trigger with this code

    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    using System.IO;

    public static void Run(HttpRequest req, ILogger log ,out string primaryOutputSbMsg , out string secondaryOutputSbMsg)
    {

      // Primary is Production, Secondary is Test  
     
    string body = new StreamReader(req.Body).ReadToEnd();  
    primaryOutputSbMsg = body;  
    secondaryOutputSbMsg = body;  
    

    }

    Then created the configuration below in the "Integration" option

    64283-image.png

    I selected the Azure Service Bus option from the drop down box, created a connection to my Production Service Bus Namespace and entered the queue name and the Message Parameter Name. and repeated the same process for Test.

    The Message Parameter Name in the config needs to be the same as the variables in the code (primaryOutputSbMsg and secondaryOutputSbMsg)

    Then it just works as expected and we can deploy the Azure Function App in APIM.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.