Integration bus for synchronizing form submission

Ajai K M asked on July 31, 2015 10:55

Hi all,

I am working on Kentico 8.2 I am developing an integration bus that used to synchronize data(outbound only) to a third-party system. The scenario is when someone submits a Kentico form from a website page i need to send the captured form submission data to the external system.So i am created a integration connector by inheriting BaseIntegrationConnector and configured successfully it with kentico backend.

But the problem was the ProcessInternalTaskAsync method was not getting triggered on the from submission.Any idea on this?

Given below is the code that i have tried.

[assembly: RegisterCustomClass("MyIntegrationConnector ", typeof(MyIntegrationConnector ))]
public class MyIntegrationConnector : BaseIntegrationConnector
{
     public override void Init()
     {
     ConnectorName = GetType().Name; 
             ObjectIntegrationSubscription objSubscription = new ObjectIntegrationSubscription(ConnectorName,      TaskProcessTypeEnum.AsyncSnapshot, TaskTypeEnum.All,sitename, PredefinedObjectType.BIZFORM, null);

            SubscribeTo(objSubscription);
      }

      public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj,        TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string              siteName, out string errorMessage)
      {
        //my code tosend data to third party system
      }
}

Any help will be appreciated

Thanks

Recent Answers


Brenden Kehren answered on July 31, 2015 13:41

You might check out the article Bryan Soltis just wrote on this process.

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on July 31, 2015 17:07

Sorry for asking this simple question, but have you enabled integration bus? https://docs.kentico.com/display/K8/Enabling+the+integration+bus

0 votesVote for this answer Mark as a Correct answer

Ajai K M answered on July 31, 2015 17:13 (last edited on July 31, 2015 17:16)

Hi,

I have already enabled that.I mentioned that i am configured integarion bus successfully with kentico back end.

Every example i have seen the synchronization of UserInfo and document, buit here i needsthe integarion bus that synchronize form submission from kentico

Thanks

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on July 31, 2015 17:32

I can see you've missed following line of code at the beginning of your init method:

ConnectorName = GetType().Name; 

As far as I know it is required.

0 votesVote for this answer Mark as a Correct answer

Ajai K M answered on July 31, 2015 19:49 (last edited on July 31, 2015 19:51)

Hi Roman Hutnyk,

I have already added that in my code, forget to mention in the question.I checked my integration bus with user info object and it seems working fine,the asynchronous method was triggered.That means no error in the bus configuration. But the problem was it not triggering on form submission.

Do I need to something additional to make it triggered on form submission or I miss something in my code? Any idea on this?

Thanks

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on August 1, 2015 20:49

It looks like you have subscription for object type BIZFORM, which will be triggered whenever you create/update biz form, but you need a subscription for biz form item. Not sure there is one. If there is no, you'll need to add a handler for biz form item inserted/updated after, where you'll need to register appropriate task.

0 votesVote for this answer Mark as a Correct answer

Ajai K M answered on August 3, 2015 10:53 (last edited on August 3, 2015 11:05)

Hi Roman Hutnyk,

I have already added the handler for biz form.I am sharing my code below, that will not working. Also i am not sure how to register the task in the event handler that you mentioned.

    [MyIntegrationConnectorLoader]
public partial class CMSModuleLoader
{
    private class MyIntegrationConnectorLoader : CMSLoaderAttribute
    {
        public override void Init()
        {
            ClassHelper.OnGetCustomClass += GetCustomClass;

            BizFormItemEvents.Insert.After += Insert_After;
            BizFormItemEvents.Update.After+=Update_After;
        }


        private void Insert_After(object sender, BizFormItemEventArgs e)
        {
         IntegrationHelper.ProcessTasks("MyIntegrationConnector", true);

        }

        private void Update_After(object sender, BizFormItemEventArgs e)
        {
            IntegrationHelper.ProcessTasks("MyIntegrationConnector", true);
        }

        private static void GetCustomClass(object sender, ClassEventArgs e)
        {
            if(e.Object==null)
            {
                switch (e.ClassName)
                {
                    case "MyIntegrationConnector":

                   e.Object=new MyIntegrationConnector();
                        break;
                }
            }
        }
    }
    }

Can you please check anything wrong here? Or do i miss something ?

Thanks

0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on August 4, 2015 09:06

Hi,

I tried that on version 8.2 and it seems to work fine, whenever I fill the form on the live site and submit it, the new task is created in Integration bus application. I am using the following code:

public class SampleIntegrationConnector : BaseIntegrationConnector
{
    #region "Initialization (subscribing)"

    /// <summary>
    /// Initialize connector name and register subscriptions.
    /// </summary>
    public override void Init()
    {
        // Initialize connector name (it has to match the code name of connector stored in DB)
        ConnectorName = GetType().Name; 

        SubscribeToObjects(TaskProcessTypeEnum.AsyncSnapshot, "bizformitem.bizform.contactus"); // change the "contactus" to the code name of your form
    }

    #endregion

    #region "Internal (outcoming) tasks"

    public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage)
    {
        try
        {
            if (infoObj.TypeInfo.ObjectType == "bizformitem.bizform.contactus")
            {
                string value = infoObj.GetValue("ColumnName").ToString(); // gets value out of form
            }
            errorMessage = null;
            return IntegrationProcessResultEnum.OK;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            return IntegrationProcessResultEnum.Error;
        }
        finally
        {
            // Clear translations cached during TranslateColumnsToExternal which internally calls GetExternalObjectID, GetExternalDocumentID
            // This call is optional but recommended in the case where eg. collision of code names can occur
            ClearInternalTranslations();
        }
    }

Could you please let us know if that helps?

Best regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

Ajai K M answered on August 5, 2015 07:31

Hi Roman Koníček,

Thank you for your support.I am happy to inform that, the code works fine. Now it triggers my ProcessInternalTaskAsync method.

But i have some doubts. Based on my understanding the Init() method trigger's only once, what happens if the site admin creates a new form in back end, how can we make sure the new form submission will also be triggered? How can i achieve this in a more generalized way. Suppose i have a n number of forms, and i need to synchronize each form submission. Is there any way to do that?

Hope you get my point.

Thanks

0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on August 5, 2015 12:30

Hi Ajai,

In case you want to apply the subscription to multiple forms rather than on specified in my previous example, you could do the following change: SubscribeToObjects(TaskProcessTypeEnum.AsyncSnapshot, "bizformitem.bizform.%");

You can notice that I have replaced the name of the form with %. This should do the trick. Could you please let me know if that covers your needs?

Best regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

Ajai K M answered on August 5, 2015 13:32 (last edited on August 5, 2015 14:05)

Hi Roman Koníček,

Thank you very much for that trick.Now it works perfectly for all forms.I have one more doubt.

Suppose my external third party system was down due to some reasons, when the form submission happens; at that time whether the integration bus will send data to my external system? Based on my understanding (based on the Kentico documentation)Integration bus has a Queue system that will take care in such situations.Is that right?

Or do I need some write some code to check whether task queue has some data,then fetch the information from the queue and process it later? If that is the case can you please share some codes or advice me how to proceed on that.

Thanks

0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on August 5, 2015 14:06

Hi Ajai,

I am happy to hear that now it is working as you need.

Regarding your question, in case you are using asynchronous processing of the tasks then when something happens (your third party system is down), the system logs the tasks into the queue and you can process them any time later.

Best regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

Ajai K M answered on August 5, 2015 14:19 (last edited on August 5, 2015 14:30)

Hi Roman Koníček,

I am using asynchronous processing.But i need clarity on what you said system logs the tasks into the queue and you can process them any time later?How the integration bus knows the external system is down? Is the integration bus takes care of fetching and resending of data on certain intervals(until it succeed) since it failed to connect the external system anytime?

If that is not the case how can I read the task from the kentico system log and process it along with the data, as you mentioned ?

Do you have any code samples available?

Thanks

0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on August 6, 2015 11:10

Hi Ajai,

If processing of the task fails, the task will be still sitting in the queue. Whether you want to delete it or keep it there if processing fails that depends on your implementation.

You will process the task with the external system (again this implementation is up to you), but once you submit the data there you will return the result of that operation - OK, Error or ErrorAndSkip. That basically says to the connector what should happen next. For example if you return OK, the task is removed from the queue. As for the code examples, have you already seen the Integration bus webinar? If not I would definitely recomnend to take a closer look at it:

http://devnet.kentico.com/articles/integration-bus

Best regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.