tailieunhanh - The Real MTCS SQL Server 2008 Exam 70/432 Prep Kit- P113
The Real MTCS SQL Server 2008 Exam 70/432 Prep Kit- P113: Congratulations on your journey to become certified in SQL Server 2008. This book will help prepare you for your exam and give you a practical view of working with SQL Server 2008. | 542 Chapter 12 Service Broker you would be processing the same message over and over. This is where the RECEIVE command comes into play. The RECEIVE statement is what is used to get the messages out of the queue so that you can do something with the data in the message. The RECEIVE statement will look very similar to the SELECT statement. You can specify which columns you wish to receive and you can specify filters based on those columns if you so desire. A typical RECEIVE statement will look something like this DECLARE @message_body XML DECLARE @conversation_handle UNIQUEIDENTIFIER RECEIVE TOP 1 @conversation_handle conversation_handle @message_ body cast message_body as XML FROM MyApplication ReceivingQueue1 END CONVERSATION @conversation_handle You can also receive more than one message at one time. In order to do this you will need to receive the messages into a table and change the TOP command to a different value. You will also need to configure your process to send more than one message per conversation as all messages that are received need to be part of the same conversation. DECLARE Messages TABLE @conversation_handle uniqueidentifier message_body varbinary MAX INSERT INTO @Messages RECEIVE TOP 100 conversation_handle message_body FROM MyApplication ReceivingQueue1 At this point the message data has been received and the conversation closed. If you are sending more than one message on the conversation then you will want to put login within the receiving code so that you know when to issue the END CONVERSATION command. Once the END CONVERSATION command has been issued no new messages will be accepted on that conversation. The acknowledgment is sent to the sending service when the END CONVERSATION command is run telling it that the conversation has been completed. That calling service should then complete an END CONVERSATION command on the conversation handle which will complete the process of ending the conversation and tell the SERVICE BROKER to mark the
đang nạp các trang xem trước