Send message from Hana Cloud Integration to Azure Service Bus

This article is part of a bigger one

Goals

Create a simple flow in HCI which send an outbound message to Azure Service Bus through an Azure Function.

Prerequisites

  • An available access to Hana Cloud Platform with HCI, URI looking like https://xxxxx-tmn.hci.eu1.hana.ondemand.com
  • An SAP S account for being able to connect
  • Eclipe (flows could be created from Web UI, but I didn't how to upload artifact without eclipse) + SAP package (see later)
  • Any Azure account
  • Firefox (somewhere :))
Eclipse + SAP

I've directly download a light version of Eclipse Mars.2 (4.5.2) recommended when I wrote the article and added SAP Hana stream : https://tools.hana.ondemand.com/mars

Then I've installed, what I think, be the minimum amount of package for our goal.

You can finally add your HCP into Eclipse settings and test the connection with your credential (I've associated an email address with my S account)

Keystore

In order to send an outbound HTTP request, HCI has to be configured with a keystore, otherwise you just get failure messages. SAP recommends using KeyStore Explorer for creating this keystore.
A keystore consists in a file containing the full chain of HCI certificates + a self signed one (you might perform stronger security for real production scenarios)

HCI chain certificates (you can easily download them with firefox)

  1. DigiCert Baltimore Root
  2. Verizon Public SureServer CA G14-SHA2
  3. *.hci.eu.hana.ondemand.com

Create now a new self signed Key Pair

  • RSA : 2048
  • Version : 3
  • Signature Algorithm : SHA256 with RSA

Finally from Eclipse, right click on our tenant and click on Deploy Artifacts for pushing our newly created keystore

You should be able to see it in the Deployed Artifacts view

  • synchronized in the Component Status View

  • in the HANA Operation View

Creating Azure Function

Creating a new Azure Function is easy, however I've faced some limitation with the Brokered Message and javascript language. Impossible to edit the customProperties of one message, had to fall back to C# language.

(json version of above configuration)

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "type": "serviceBus",
      "name": "outputSbMsg",
      "queueName": "queuename",
      "connection": "connection",
      "accessRights_": "Send",
      "direction": "out"
    }
  ],
  "disabled": false
}

and the C# function itself, adding a custom property (we use customer property for afterward message routing)
some extra details for parameters could be found on this cheat sheet. Might be outdated for some information (2014)

#r "Microsoft.ServiceBus"
using Microsoft.ServiceBus.Messaging;  
using System.Net;

public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log,out BrokeredMessage outputSbMsg)  
{
    log.Info("C# HTTP trigger function processed a request.");

    dynamic data = req.Content.ReadAsStringAsync().Result;

    outputSbMsg = new BrokeredMessage(data);
    outputSbMsg.Properties.Add("fromsystem","sap");
    return req.CreateResponse(HttpStatusCode.OK, "Hello");
}
Basic HCI flow

In HANA, create a new package from the Design section, then create a new Process Integration artifact

Per default you will get the following simple flow

  • Remove Sender
  • Add a Timer Start Event configured with Run Once
  • Add a Content Modified with any Message Body
  • Create connection between all Integration block

Create a connection from the End block until the Receiver (Azure Function) and choose HTTP

and configure necessary Azure Function Address and authentication token.

And voilĂ  !

Test & monitoring

Let's deploy and check what's going on in the Operation View

if you had a keystore issue, you would see the error message in below screen

[CAMEL][IFLOW][ERROR] : Integration flow failed.
  [CAMEL][IFLOW][EXCEPTION] : java.util.concurrent.TimeoutException
  [CAMEL][IFLOW][UNRESOLVED] : Unresolved dependency: (objectClass=com.sap.esb.camel.http.ahc.configurer.AHCConfigFactory)
  [CAMEL][IFLOW][UNRESOLVED] : Unresolved dependency: (&(keystore=default)(objectClass=com.sap.esb.security.KeyCertificateAccessor))

if everything goes fine, in Monitor Message Processing you would see one message with Completed status

in Azure Function Monitor part, you can see a call of your function

And finally

First part done ! Next part involves a lot of SAP \o/

Fabien Camous

Read more posts by this author.