You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/database-engine/service-broker/lesson-2-creating-an-internal-activation-procedure.md
+73-73Lines changed: 73 additions & 73 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,95 +22,95 @@ In this lesson, you will learn to create a stored procedure to process messages
22
22
23
23
### Switch to the AdventureWorks2008R2 database
24
24
25
-
- Copy and paste the following code into a Query Editor window. Then, run it to switch context to the AdventureWorks2008R2 database.
26
-
```
27
-
USE AdventureWorks2008R2;
28
-
GO
29
-
```
25
+
- Copy and paste the following code into a Query Editor window. Then, run it to switch context to the AdventureWorks2008R2 database.
26
+
27
+
```sql
28
+
USE AdventureWorks2008R2;
29
+
GO
30
+
```
30
31
31
32
### Create an internal activation stored procedure
32
33
33
-
- Copy and paste the following code into a Query Editor window. Then, run it to create a stored procedure. When it is run, the stored procedure keeps receiving messages as long as there are messages in the queue. If the receive times out without returning a message, the stored procedure ends. If the received message was a request message, the stored procedure returns a reply message. If the received message is an **EndDialog** message, the stored procedure ends the target side of the conversation. If the received message is and **Error** message, it rolls back the transaction.
34
-
```
35
-
CREATE PROCEDURE TargetActivProc
36
-
AS
37
-
DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;
38
-
DECLARE @RecvReqMsg NVARCHAR(100);
39
-
DECLARE @RecvReqMsgName sysname;
40
-
41
-
WHILE (1=1)
42
-
BEGIN
34
+
- Copy and paste the following code into a Query Editor window. Then, run it to create a stored procedure. When it is run, the stored procedure keeps receiving messages as long as there are messages in the queue. If the receive times out without returning a message, the stored procedure ends. If the received message was a request message, the stored procedure returns a reply message. If the received message is an **EndDialog** message, the stored procedure ends the target side of the conversation. If the received message is and **Error** message, it rolls back the transaction.
35
+
36
+
```sql
37
+
CREATE PROCEDURE TargetActivProc
38
+
AS
39
+
DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;
40
+
DECLARE @RecvReqMsg NVARCHAR(100);
41
+
DECLARE @RecvReqMsgName sysname;
43
42
44
-
BEGIN TRANSACTION;
43
+
WHILE (1=1)
44
+
BEGIN
45
45
46
-
WAITFOR
47
-
( RECEIVE TOP(1)
48
-
@RecvReqDlgHandle = conversation_handle,
49
-
@RecvReqMsg = message_body,
50
-
@RecvReqMsgName = message_type_name
51
-
FROM TargetQueueIntAct
52
-
), TIMEOUT 5000;
46
+
BEGIN TRANSACTION;
47
+
48
+
WAITFOR
49
+
( RECEIVE TOP(1)
50
+
@RecvReqDlgHandle = conversation_handle,
51
+
@RecvReqMsg = message_body,
52
+
@RecvReqMsgName = message_type_name
53
+
FROM TargetQueueIntAct
54
+
), TIMEOUT 5000;
53
55
54
-
IF (@@ROWCOUNT = 0)
55
-
BEGIN
56
-
ROLLBACK TRANSACTION;
57
-
BREAK;
58
-
END
56
+
IF (@@ROWCOUNT =0)
57
+
BEGIN
58
+
ROLLBACK TRANSACTION;
59
+
BREAK;
60
+
END
59
61
60
-
IF @RecvReqMsgName =
61
-
N'//AWDB/InternalAct/RequestMessage'
62
-
BEGIN
63
-
DECLARE @ReplyMsg NVARCHAR(100);
64
-
SELECT @ReplyMsg =
65
-
N'<ReplyMsg>Message for Initiator service.</ReplyMsg>';
### Alter the target queue to specify internal activation
90
92
91
-
- Copy and paste the following code into a Query Editor window. Then, run it to specify that Service Broker activate the **TargetActiveProc** stored procedure to process messages from **TargetQueueIntAct**. Service Broker will run a copy of **TargetActiveProc** any time a message is received in **TargetQueueIntAct** and no copy of the procedure is already running. Service Broker will run additional copies of **TargetActiveProc** whenever the existing copies do not keep up with the number of incoming messages.
93
+
- Copy and paste the following code into a Query Editor window. Then, run it to specify that Service Broker activate the **TargetActiveProc** stored procedure to process messages from **TargetQueueIntAct**. Service Broker will run a copy of **TargetActiveProc** any time a message is received in **TargetQueueIntAct** and no copy of the procedure is already running. Service Broker will run additional copies of **TargetActiveProc** whenever the existing copies do not keep up with the number of incoming messages.
92
94
93
-
```
94
-
ALTER QUEUE TargetQueueIntAct
95
-
WITH ACTIVATION
96
-
( STATUS = ON,
97
-
PROCEDURE_NAME = TargetActivProc,
98
-
MAX_QUEUE_READERS = 10,
99
-
EXECUTE AS SELF
100
-
);
101
-
GO
102
-
```
95
+
```sql
96
+
ALTER QUEUE TargetQueueIntAct
97
+
WITH ACTIVATION
98
+
( STATUS =ON,
99
+
PROCEDURE_NAME = TargetActivProc,
100
+
MAX_QUEUE_READERS =10,
101
+
EXECUTE AS SELF
102
+
);
103
+
GO
104
+
```
103
105
104
106
## Next Steps
107
+
105
108
You have successfully configured AdventureWorks2008R2 to support a conversation between the **//AWDB/InternalAct/InitiatorService** and the **//AWDB/InternalAct/TargetService**. Next, you will complete a conversation using the configuration. See [Lesson 3: Beginning a Conversation and Transmitting Messages](lesson-3-beginning-a-conversation-and-transmitting-messages.md).
Copy file name to clipboardExpand all lines: docs/database-engine/service-broker/lesson-2-creating-the-initiator-database.md
+25-38Lines changed: 25 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ ms.date: "03/30/2022"
17
17
In this lesson, you will learn to create the initiator database and all the initiator Service Broker objects that are used in this tutorial. Run these steps from a copy of Management Studio that is running on the same computer as the initiator instance the Database Engine.
18
18
19
19
## Procedures
20
+
20
21
### Create a Service Broker endpoint
21
22
22
23
- Copy and paste the following code into a Query Editor window. Then, run it to create a Service Broker endpoint for this instance of the Database Engine. A Service Broker endpoint specifies the network address to which Service Broker messages are sent. This endpoint uses the Service Broker default of TCP port 4022, and specifies that remote instances of the Database Engine will use Windows Authentication connections to send messages.
@@ -64,7 +65,7 @@ In this lesson, you will learn to create the initiator database and all the init
64
65
65
66
- Copy and paste the following code into a Query Editor window. Change the file name that is specified in the BACKUP CERTIFICATE statement to refer to a folder on your system. Then, run the code to create the initiator certificate that is used to encrypt messages. The folder that you specify should have permissions that prevent access from accounts other than your Windows account and the Windows account the instance of the Database Engine is running under. For Lesson 3, you must manually copy the **InstInitiatorCertificate.cer** file to a folder that can be accessed from the target instance.
66
67
67
-
```
68
+
```sql
68
69
CREATE CERTIFICATE InstInitiatorCertificate
69
70
AUTHORIZATION InitiatorUser
70
71
WITH SUBJECT = N'Initiator Certificate',
@@ -80,7 +81,7 @@ In this lesson, you will learn to create the initiator database and all the init
80
81
81
82
- Copy and paste the following code into a Query Editor window. Then, run it to create the message types for the conversation. The message type names and properties specified here must be identical to the ones that were created in the **InstTargetDB**in the previous lesson.
82
83
83
-
```
84
+
```sql
84
85
CREATE MESSAGE TYPE [//BothDB/2InstSample/RequestMessage]
85
86
VALIDATION = WELL_FORMED_XML;
86
87
CREATE MESSAGE TYPE [//BothDB/2InstSample/ReplyMessage]
@@ -92,7 +93,7 @@ In this lesson, you will learn to create the initiator database and all the init
92
93
93
94
- Copy and paste the following code into a Query Editor window. Then, run it to create the contract for the conversation. The contract name and properties that are specified here must be identical to the contract that you will create in the **InstInitiatorDB** during the next lesson.
@@ -106,7 +107,7 @@ In this lesson, you will learn to create the initiator database and all the init
106
107
107
108
- Copy and paste the following code into a Query Editor window. Then, run it to create the queue and service that is used for the target. The CREATE SERVICE statement associates the service with the **InstInitiatorQueue**. Therefore, all messages that are sent to the service will be received into the **InstInitiatorQueue**. The CREATE SERVICE also specifies that only conversations that use the **//BothDB/ 2InstSample/SimpleContract** that was created earlier can use the service as a target service.
108
109
109
-
```
110
+
```sql
110
111
CREATE QUEUE InstInitiatorQueue;
111
112
112
113
CREATE SERVICE [//InstDB/2InstSample/InitiatorService]
@@ -119,7 +120,7 @@ In this lesson, you will learn to create the initiator database and all the init
119
120
120
121
- Copy and paste the following code into a Query Editor window. Change the FROM FILE clause to reference the folder to which you copied the **InstTargetCertficate.cer** file from step 3in Lesson 1. Then, run the code to create a target user and pull in the target certificate.
121
122
122
-
```
123
+
```sql
123
124
CREATE USER TargetUser WITHOUT LOGIN;
124
125
125
126
CREATE CERTIFICATE InstTargetCertificate
@@ -135,7 +136,7 @@ In this lesson, you will learn to create the initiator database and all the init
135
136
136
137
The following CREATE ROUTE statements assume that there are no duplicate service names in the target instance. If multiple databases on the target instance have services with the same name, use the BROKER_INSTANCE clause to specify the database on which you want to open a conversation.
137
138
138
-
```
139
+
```sql
139
140
DECLARE @Cmd NVARCHAR(4000);
140
141
141
142
SET @Cmd = N'USE InstInitiatorDB;
@@ -163,39 +164,25 @@ In this lesson, you will learn to create the initiator database and all the init
163
164
```
164
165
165
166
## Next Steps
167
+
166
168
You have successfully created the initiator databases that will be used for the tutorial. Next, you will finish configuring the target database by creating the target objects that have dependencies on initiator objects. See [Lesson 3: Completing the Target Conversation Objects](lesson-3-completing-the-target-conversation-objects.md).
Copy file name to clipboardExpand all lines: docs/database-engine/service-broker/lesson-2-creating-the-target-conversation-objects.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,15 +65,13 @@ In this lesson, you will learn to build all the objects that enable a database t
65
65
```
66
66
67
67
## Next Steps
68
+
68
69
You have successfully configured **TargetDB** to support a conversation between it and the **InitiatorDB**. Next, you will configure the **InitiatorDB** to initiate a conversation to the **TargetDB**. See [Lesson 3: Creating the Initiator Conversation Objects](lesson-3-creating-the-initiator-conversation-objects.md).
69
70
70
71
## See also
71
-
[CREATE MESSAGE TYPE (Transact-SQL)](../../t-sql/statements/create-message-type-transact-sql.md)
Copy file name to clipboardExpand all lines: docs/database-engine/service-broker/lesson-3-beginning-a-conversation-and-transmitting-messages.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ ms.date: "03/30/2022"
17
17
In this lesson, you will learn to complete a simple request-reply message cycle in a system configured with an internal activation stored procedure.
18
18
19
19
## Procedures
20
+
20
21
### Switch to the AdventureWorks2008R2 database
21
22
22
23
[!INCLUDE [SQL Server Service Broker AdventureWorks2008R2](../../includes/service-broker-adventureworks-2008-r2.md)]
@@ -96,15 +97,13 @@ In this lesson, you will learn to complete a simple request-reply message cycle
96
97
- When you run the END CONVERSATION statement for the initiator, Service Broker sends an **EndDialog** message to the **TargetQueueIntAct** queue. The **TargetActiveProc** procedure receives the **EndDialog** message and issues an END CONVERSATION that ends the target side of the conversation.
97
98
98
99
## Next Steps
100
+
99
101
You have successfully completed a request-reply message cycle between the **//AWDB/InternalAct/InitiatorService** and the **//AWDB/InternalAct/TargetService**. You can repeat the steps in this lesson as many times as you want to transmit a request-reply pair of messages. When you have finished investigating the SEND and REPLY statements, you can drop all the objects that were used by the conversation. For more information, see [Lesson 4: Dropping the Conversation Objects](lesson-4-dropping-the-conversation-objects.md).
0 commit comments