title: Service Broker with active stored procedure in SQL Server
body: <p>I create a service broker by two SQL Server instances based on this link 
  <a href="http://www.sqlservercentral.com/articles/Service+Broker/2797/" rel="nofollow noreferrer">enter link description here</a></p>
  
  <p>Everything is ok, so my message is send by serverA as you can see :</p>
  
  <pre><code>Declare @ConversationHandle uniqueidentifier
  
  Begin Transaction
  Begin Dialog @ConversationHandle
   From Service SenderService
   To Service 'ReceiverService'
   On Contract SampleContract
   WITH Encryption=off;
  SEND 
        ON CONVERSATION @ConversationHandle
        Message Type SenderMessageType
    ('&lt;test&gt;test&lt;/test&gt;')
  Commit
  </code></pre>
  
  <p>In Server B I receive the message using this code :</p>
  
  <pre><code>Declare @ConversationHandle as uniqueidentifier
  Declare @MessageBody as nvarchar(max)
  Declare @MessageType as sysname
  
  Begin Transaction
  Print 'Started Receiving ';
  
      RECEIVE top (1)
            @MessageType = message_type_name,
            @ConversationHandle = conversation_handle,
          @MessageBody = message_body
      FROM TargetQueue;
  
      if @MessageType = 'SenderMessageType'
            Begin
                  SEND 
                        ON CONVERSATION @ConversationHandle
                        Message Type ReceiverMessageType
                        ('Message is received')
                  END Conversation @ConversationHandle
            END
  
      Commit
  </code></pre>
  
  <p>This code receives the message, but for processing the message with this code I have to run the above code every time (manually). I want to make it automatic, I mean if the message is received, the above query is executed automatically.</p>
  
  <p>Should I create a stored procedure with while 1=1 condition to process it?</p>