Connect your ERP-System to Mobile Field Report

May 28 2013 1:55 PM

As the community of Mobile Field Report (MFR) is growing, we are also trying to provide the best tools and extensibility points for developers. In the recent post we have introduced MFR OData API endpoint that provides very flexible way how to get data from MFR. Today we are releasing completely new section in MFR portal dedicated for developers.

You can find OData endpoint URL there as well as links to further examples. But what is brand new and what I will introduce today is MFR support for AMQP Messaging.

AMQP in Mobile Field Report

AMQP (link http://www.amqp.org/) stays for Advanced Message Queuing Protocol which is a new standard for inter-portable, cross-platform messaging. MFR is using this protocol to broadcast events (like job created, job deleted and others) and to notify other potential systems or plugins. This means that every system can listen to MFR events and operate on them. The example could be propagating changes from MFR to company ERP system. I will show how to get started with MFR messaging in few steps.

To start using MFR messaging you need to activate it first. To do this open MFR portal and navigate to Account Settings / Developers section. Than click Activate button at the bottom commands section. This action should prepare a message bus and provide all the necessary credentials for you.

Next step is to create a subscription. Subscription defines a consumer of events. MFR is broadcasting events to all specified subscriptions therefor you need to have at least one. You will typically create a separate subscription for every system that you will integrate with MFR. To create it navigate to Subscriptions tab and create one.

Now you have everything prepared for integrating with MFR. I will post here a quick example how to consume MFR events in c# but you can use any other language that has a port to AMQP. For java you can take a look at this document describing how to bridge JMS to AMQP (http://msdn.microsoft.com/en-us/library/windowsazure/jj835806.aspx).

C# example

Start with creating a c# console application in visual studio. Next step is to add a reference to Microsoft.ServiceBus. You can do this using a NuGet package or direct downloading assembly.

Install Package with NuGet

Next you need to get credentials and connection strings from MFR portal.

Credentials from MFR Portal

private const string MESSAGE_BUS_URL = "sb://mfr-debug.servicebus.windows.net/";
private
const string TOPIC_NAME = "65536";
private
const string TOPIC_AUTH_KEY = "listenRule";
private
const string TOPIC_KEY = "SSaLuVWan9mbCBc1nj5M21ZPGkhid+LUFz1MoYLLi1A=";
private
const string SUBSCRIPTION_NAME = "test";

TokenProvider sasTP =
   
TokenProvider.CreateSharedAccessSignatureTokenProvider(TOPIC_AUTH_KEY, TOPIC_KEY);

MessagingFactory messagingFactory =
   
MessagingFactory.Create(MESSAGE_BUS_URL, sasTP);

SubscriptionClient messageReceiver =
    messagingFactory.CreateSubscriptionClient(TOPIC_NAME, SUBSCRIPTION_NAME);

while (true)
{

    var message = messageReceiver.Receive();
   
if (message != null)
    {
       
Console.WriteLine("eventType: " + message.Properties["eventType"]);
    }

    message.Complete();
   
Thread.Sleep(2000);

}

The sample has a very simple functionality. It just loops and reads a message from MFR and writes it to the console. To be actually able to read a message from MFR message bus, you need to create a SubscriptionClient. To create SubscriptionClient you need to get a MessagingFactory based on the credentials located in the portal.

If you run this console application, it should be writing the events from MFR to the console. You just need to invoke some changes, like create or delete contact in MFR portal.

Result in the consol

You can download full example here
Download

That’s how you can listen to events from MFR. You can see that from integrating other systems with MFR is becoming a very easy task. Follow our blog to see more upcoming features.