Presentation is loading. Please wait.

Presentation is loading. Please wait.

Service Broker in action

Similar presentations


Presentation on theme: "Service Broker in action"— Presentation transcript:

1 Service Broker in action
Tomasz

2 SQLSat Kyiv Team Olena Smoliak Oksana Borysenko Vitaliy Popovych
Yevhen Nedashkivskyi Mykola Pobyivovk

3 3 Sponsor Sessions at 12:40 Don’t miss them, they might be providing some interesting and valuable information! Room A Room B Room C 13: :15 Intapp DB Best NULL 13: :50 Microsoft DevArt JetBrains NULL means no session in that room at that time 

4 Our Awesome Sponsors

5 Session will begin very soon :)
Please complete the evaluation form from your pocket after the session. Your feedback will help us to improve future conferences and speakers will appreciate your feedback! Enjoy the conference!

6 Tomasz Libera DB Developer - WSZiB Krakow
Polish SQL Server User Group Association plssug.org.pl Member of The Board Krakow Local Group Leader Certificates MCT, MCSE MCITP-DBA, MCITP-DD… Interests mountain biking MTB marathons

7 Університет управління та банківської справи пропонує навчання на таких академічних ступнях: бакалавр, спеціаліст, магістр і післядипломна освіта. Вуз оснащений є у власну дидактичну базу.

8 Agenda Introduction, History Anatomy of Service Broker
Message, Contract, Service First Conversation Activation Troubleshooting SB as SQL Server Agent

9 Introduction Introduced in SQL Server 2005
Asynchronous messaging system Very little support in SSMS GUI Specific T-SQL clauses SEND RECEIVE Receiving and processing messages is done on demand or based on activation

10 Send and Receive SEND puts a message on a queue (equivalent of INSERT)
SEND ON MESSAGE TYPE [//PLSSUG/SQLSB/MyMsg] RECEIVE removes a message from a queue (equivalent of SELECT) RECEIVE TOP(1) @Ch = conversation_handle, @MsgTypeName = message_type_name, @MsgBody = CAST(message_body AS XML) FROM ReceiverQueue

11 History SQL 2005 SQL 2008 SQL 2012 SQL 2014 SQL 2016
Multicast - Messages can be sent to multiple target services message_enqueue_time Poison message handling can be disabled AlwaysOn support REBUILD QUEUE Service Broker introduction SQL 2005 SQL 2008 SQL 2012 SQL 2014 SQL 2016 Conversation priorities SSBdiagnose utility Alternate poison message handling Performance objects/counters No changes

12 Agenda Intruduction, History Anatomy of Service Broker
Message, Contract, Service First Conversation Activation Troubleshooting SB as SQL Server Agent

13 Dialog Must be started before exchanging messages
Messages are being sent in the same database in different databases in the same instance in different databases in different instances BEGIN DIALOG FROM SERVICE [//PLSSUG/SQLSB/SenderService] TO SERVICE '//PLSSUG/SQLSB/ReceiverService', 'CURRENT DATABASE' ON CONTRACT [//PLSSUG/SQLSB/Contract] WITH ENCRYPTION = OFF;

14 Message VARBINARY(MAX) structure Defines the name and the validation
NONE (default) – no validation is performed. EMPTY - message body must be NULL. WELL_FORMED_XML (most popular) - must contain well-formed XML. VALID_XML WITH SCHEMA COLLECTION - message body must contain XML that complies with a schema in the specified schema collection XML is implemented internally in SQL Server as a binary structure

15 Service Broker Anatomy
Queue - sys.service_queue An object which hold messages Service - sys.services Messages are being sent to services which placed them on the queue Message – sys.service_message_types The name and the validation Contract - sys.service_contracts What types of messages can be used by sender and receiver Route – sys.routes Remote service binding - sys.remote_service_binding

16 Agenda Introduction, History Anatomy of Service Broker
Message, Contract, Service First Conversation Activation Troubleshooting SB as SQL Server Agent

17 Message exchange in Service Broker
SENDER SERVICE RECEIVER SERVICE SENDER QUEUE RECEIVER QUEUE SYS. TRANSMISSION QUEUE SYS. TRANSMISSION QUEUE request massage STORED PROCEDURE STORED PROCEDURE

18 Message exchange in Service Broker
SENDER SERVICE RECEIVER SERVICE SENDER QUEUE RECEIVER QUEUE SYS. TRANSMISSION QUEUE SYS. TRANSMISSION QUEUE response messages STORED PROCEDURE STORED PROCEDURE

19 DEMO1: Setup DEMO2: First conversation
Create message types contracts services queues Begin conversation Send and receive messages End conversation

20 /SQL/ServiceBroker/EndDialog
MessageType that marks the endpoint as closed When endpoint receives the EndDialog message, it can’t send messages on the dialog Must be sent by both services END Could be sent because of an error END WITH ERROR = 31472 DESCRIPTION = 'Something goes wrong' To cleanup orphaned dialogs END WITH CLEANUP

21 DEMO2B: EndDialog END CONVERSATION END CONVERSATION WITH ERROR

22 Agenda Introduction, History Anatomy of Service Broker
Message, Contract, Service First Conversation Activation Troubleshooting SB as SQL Server Agent

23 Activation Activation lunches the process in response to the enqueue receiving messages Internal activation - runs the stored procedure within the database. External activation - external process (.NET application) , processes messages which are waiting in the queue. Both types of activation has ability to launch multiple processes to handle large volume of messages in parallel

24 DEMO3: Activation Create activation stored procedures
For Sender For Receiver Alter queue to enable activation Test activation

25 Agenda Introduction, History Anatomy of Service Broker
Message, Contract, Service First Conversation Activation Troubleshooting SB as SQL Server Agent

26 Troubleshooting Transmission queue Poison message Error Handling

27 Transmission queue sys.transmission_queue One in every database.
Stores messages temporarily before they reach destination Important for troubleshooting - transmission_status Is used: The destination is on a different SQL Server instance The destination is disabled STATUS=OFF (poison message) Service Broker is disabled (after restore/attach) The destination is unknown

28 Poison messages When error occurs during message processing – transaction is rolled back and message is going back to the queue After 5 rollbacks in a row – a queue will be disabled to stop the poison message SOLUTION: prevent

29 DEMO4: transmission queue
Sending message to disabled queue Disabled ServiceBroker Poison message

30 /SQL/ServiceBroker/Error
MessageType when a dialog is ended with error When endpoint receives the Error message, neither side of conversation can send messages Can contain error number and description Usually used in CATCH block END WITH ERROR = 5555 DESCRIPTION = 'Incorrect address'

31 DEMO5: Error Handling TRY…CATCH code in activated procedures

32 Do you want more? Books Links
Pro SQL Server 2008 Service Broker - Klaus Aschenbrenner Inside Microsoft SQL Server 2008 T-SQL Programming (Roger Wolter chapter) Links RUSANU – the best source about troubleshooting Service Broker SQLDay 2013 | DBA/DEV Track | Denny Cherry - Getting SQL Service Broker Up and Running SQL Server Service Broker Scheduling Jobs in SQL Server Express SQL Server 2012 – What’s new in Service Broker How to use Service Broker to scale out SQL Server database applications

33 For help, contact me:

34 THANK YOU


Download ppt "Service Broker in action"

Similar presentations


Ads by Google