03/18/2015 08:11 PM Calling external web service when order is placed online
Virto Commerce

Calling external web service when order is placed online

Updated:

Summary

It is a common integration scenario when order needs to be submitted to external/backend system when it is placed online for further processing. The backend service is guaranteed to be always available so such case needs to be handled. This document explores such scenario and provides guidance on implementing solution to handle this.

Overview

The basic idea is to save order to the queue (service bus queue or storage queue) on checkout process. Then scheduled job retrieves order from the queue and tries to send it to the web service. If web service is not available then order remains in the queue for the next try.

Implementation

Storage Queue Implementation

Virto commerce framework provides all needed functionality to implement such task:

  1. Frontend calls workflow “ShoppingCartCheckoutWorkflow” when checkout is proceeded. This workflow can be extended with new activity that writes order to the queue. Read more about creating workflow and activity: docs/old-versions/vc113devguide/working-with-orders/creating-workflow-activities
  2. There are ready classes for accessing Azure queue: AzureQueueReader and AzureQueueWriter (namespace „VirtoCommerce.Foundation.Data.Azure.CQRS“ in „CommerceFoundation.Data.Azure“ assembly). Writer should be used in workflow activity and Reader in job.
  3. Job implementation and registering in to the scheduler: docs/old-versions/vc113devguide/architecture/long-running-tasks

Service Bus Queue Implementation

In this scenario you will need to configure service bus. Service bus also offers advanced security and access management.

  1. Frontend calls workflow “ShoppingCartCheckoutWorkflow” when checkout is proceeded. This workflow can be extended with new activity that writes order to the service bus queue. Read more about creating workflow and activity: docs/old-versions/vc113devguide/working-with-orders/creating-workflow-activities
  2. To begin using Service Bus queues in Windows Azure:
  1. Job implementation and registering in to the scheduler: docs/old-versions/vc113devguide/architecture/long-running-tasks
  2. Subscribe to the topic in the service bus queue to receive notifications when new item is added and submit the order to the external service.

Other things that may need to consider

Microsoft Azure supports two types of the queue mechanisms: Storage queue and Service Bus queue. Here is detailed comparison of them: http://msdn.microsoft.com/en-us/library/windowsazure/hh767287.aspx

Integrating with on-premise web service means to expose it to security risks. Microsoft Azure provides Service Bus Relay Service that helps to establish communication between two applications in more secure and flexible way: