Search code examples
biztalkmessagepipeline

In Disassembler pipeline component - Send only last message out from GetNext() method


I have a requirement where I will be receiving a batch of records. I have to disassemble and insert the data into DB which I have completed. But I don't want any message to come out of the pipeline except the last custom made message.

I have extended FFDasm and called Disassembler(), then we have GetNext() which is returning every debatched message out and they are failing as there is subscribers. I want to send nothing out from GetNext() until Last message.

Please help if anyone have already implemented this requirement. Thanks!


Solution

  • If you want to send only one message on the GetNext, you have to call on Disassemble method to the base Disassemble and get all the messages (you can enqueue this messages to manage them on GetNext) as:

     public new void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
     {
        try
        {    
           base.Disassemble(pContext, pInMsg);
    
           IBaseMessage message = base.GetNext(pContext);
           while (message != null)
           {    
               // Only store one message                   
               if (this.messagesCount == 0)
               {
                  // _message is a Queue<IBaseMessage>
                  this._messages.Enqueue(message);
    
                  this.messagesCount++;
               }
    
               message = base.GetNext(pContext);
           }              
        }
        catch (Exception ex)
        {
           // Manage errors 
        }
    

    Then on GetNext method, you have the queue and you can return whatever you want:

    public new IBaseMessage GetNext(IPipelineContext pContext)
    {
       return _messages.Dequeue();
    }