"certificate not found" for second receiver
I am trying to test load balancing between multiple broker service instances. I have set up one sender and two receivers. When I tried sending a lot of messages from the sender, I noticed that all messages were being received by receiver 1 alone. While I am able to communicate between sender and receiver 1, I am not able to send message to the second receiver (I stopped the first receiver instance to find this out). I receive the "certificate not found" error in the Profiler for the second receiver. The code for my second receiver is very similar to the first one.
I am dumping in the full code down here. I appreciate if someone can figure out what is wrong. Thanks
Sender:
use [master];
go
create master key encryption by password = 'masterhello1';
go
create certificate TrpCertServ1
with subject = 'TrpCertServer1',
start_date = '06/01/2005';
go
--make sure the cert exist
select * from sys.certificates;
go
--dump out the public key of the cert to a file
--this will then be exchanged with the other instance
--make sure that the path you define below can be accessed
--by sql server. The file needs to be copied over to server 2
BACKUP CERTIFICATE TrpCertServ1
TO FILE = 'c:\amit\Official\Service Broker\certs\TrpCertServ1Pub.cer';
go
--you need to create an endpoint in order to enable communication
--outside of this instance
CREATE ENDPOINT SSB1
STATE = STARTED
AS TCP
(
LISTENER_PORT = 4021
)
FOR SERVICE_BROKER
(
AUTHENTICATION = CERTIFICATE TrpCertServ1,
ENCRYPTION = REQUIRED
);
go
USE master ;
GO
ALTER ENDPOINT SSB1
FOR SERVICE_BROKER ( MESSAGE_FORWARDING = ENABLED,
MESSAGE_FORWARD_SIZE = 10 ) ;
GO
--check that the endpoint has been created
select * from sys.endpoints;
go
--create a login and a user which you eventually will assign a public
--key from the cert in the remote master db to
create login remconnlogin1
with password ='remserver@1';
go
create user remconnuser1
from login remconnlogin1;
go
--grant connect to the endpoint to the login
grant connect on endpoint::ssb1 to remconnlogin1
go
--now is time to go over to server 2 and do similar tasks
--but first make sure that the cert you dumped out above can be
--available for server 2
--Step 2
-- you have now done the similar setup in server 2,
--and you should now do the final setup in master
--where you create a certificate from server 2's public
--cert and assigns it to the user created above
--uncomment from here to go and execute
create certificate TrpCertServ2Pub
authorization remconnuser1
from file = 'C:\amit\Official\Service Broker\certs\TrpCertServ2Pub.cer';
go
--adding for new receiver
create certificate TrpCertServ3Pub
authorization remconnuser1
from file = 'C:\amit\Official\Service Broker\certs\TrpCertServ3Pub.cer';
go
-- end of addition
use master;
go
--create the database
create database [rem_ssb1];
go
use [rem_ssb1];
go
--set master key
create master key
encryption by password = 'hellodb1';
create certificate DlgCertServ1Db1
with subject = 'DlgCertServ1Db1',
start_date = '06/01/2005'
active for begin_dialog = on;
go
--make sure the cert exist
select * from sys.certificates;
go
--dump out the public key of the cert to a file
--this will then be exchanged with the other instance
--make sure that the path you define below can be accessed
--by sql server. The file needs to be copied over to server 2
BACKUP CERTIFICATE DlgCertServ1Db1
TO FILE = 'c:\amit\Official\Service Broker\certs\DlgCertServ1Db1Pub.cer';
go
--create a user which you eventually will assign a public
--key from the cert in the remote db to
create user remdlguser1
without login;
go
--Step 2
create certificate DlgCertServ2Db2Pub
authorization remdlguser1
from file = 'c:\amit\Official\Service Broker\certs\DlgCertServ2Db2Pub.cer';
go
-- adding content for new receiver
create certificate DlgCertServ3Db3Pub
authorization remdlguser1
from file = 'c:\amit\Official\Service Broker\certs\DlgCertServ3Db3Pub.cer';
go
-- end of addition
use [rem_ssb1];
go
-- we need two message types
CREATE MESSAGE TYPE [sendmsg]
VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE [recmsg]
VALIDATION = WELL_FORMED_XML;
go
--create the message contract
--and define who sends what
CREATE CONTRACT [Ctract]
(
[sendmsg]
sent by initiator,
[recmsg]
sent by target
);
go
--create the queue, at this stage we do not care
--about activation
CREATE QUEUE q1
with status = ON;
go
--we need a service
CREATE SERVICE [rem_s1]
on queue q1
(
[Ctract]
);
go
--create a route to the remote service, we know it'll be called rem_s2
create route [rem_s2_route]
with
service_name = 'rem_s2',
address = 'TCP://127.0.0.1:4022';
go
--drop route [rem_s2_route]
-- adding for new route
create route [rem_s3_route]
with
service_name = 'rem_s2',
address = 'TCP://127.0.0.1:4023';
go
-- end of addition
select * from sys.routes
--as we'll be doing encrypted dialogs we need a remote service bindin
CREATE REMOTE SERVICE BINDING [myRms]
TO SERVICE 'rem_s2'
WITH USER = remdlguser1,
ANONYMOUS=Off
--give the user send rights on the service
grant send on service::rem_s1 to remdlguser1;
go
use [rem_ssb1];
go
-start the dialog and send a message
-uncomment from here until the following go statement and run
DECLARE @h uniqueidentifier --conversation handle
DECLARE @msg xml; --will hold the message
BEGIN DIALOG CONVERSATION @h
FROM SERVICE rem_s1
TO SERVICE 'rem_s2'
ON CONTRACT [Ctract];
SET @msg = '<hello00/>';
SEND ON CONVERSATION @h
MESSAGE TYPE [sendmsg]
(@msg);
RECEIVER 1:
--Step 1
use [master];
go
create master key encryption by password = 'masterhello2';
go
create certificate TrpCertServ2
with subject = 'Transport Certificate for Server2',
start_date = '06/01/2005';
go
--make sure the cert exist
select * from sys.certificates;
go
--dump out the public key of the cert to a file
--this will then be exchanged with the other instance
--make sure that the path you define below can be accessed
--by sql server. The file needs to be copied over to server 1
BACKUP CERTIFICATE TrpCertServ2
TO FILE = 'c:\amit\Official\Service Broker\certs\2\TrpCertServ2Pub.cer';
go
--you need to create an endpoint in order to enable communication
--outside of this instance
CREATE ENDPOINT SSB2
STATE = STARTED
AS TCP
(
LISTENER_PORT = 4022
)
FOR SERVICE_BROKER
(
AUTHENTICATION = CERTIFICATE TrpCertServ2,
ENCRYPTION = REQUIRED
);
go
--check that the endpoint has been created
select * from sys.endpoints;
go
--create a login and a user which you eventually will assign a public
--key from the cert in the remote master db to
create login remconnlogin2
with password = 'pass1234$';
go
create user remconnuser2
from login remconnlogin2;
go
--grant connect on the endpoint to the login
grant connect on endpoint::SSB2 to remconnlogin2
go
--copy in the public cert from server 1 to somewhere on this server
--create a certificate from the public cert from server 1
create certificate TrpCertServ1Pub
authorization remconnuser2
from file = 'c:\amit\Official\Service Broker\certs\2\TrpCertServ1Pub.cer';
--go back to server 1 and step 2 in the script 1_setup_sec_master_server1.sql
--make sure the public cert 'TrpCertServ2Pub.cer' is available
--from server 1
use master;
go
--create the database
create database [rem_ssb2];
go
use [rem_ssb2];
go
--set master key
create master key
encryption by password = 'hellodb2';
go
create certificate DlgCertServ2Db2
with subject = 'DlgCertServ2Db2',
start_date = '06/01/2005'
active for begin_dialog = on;
go
--make sure the cert exist
select * from sys.certificates;
go
BACKUP CERTIFICATE DlgCertServ2Db2
TO FILE = 'c:\amit\Official\Service Broker\certs\2\DlgCertServ2Db2Pub.cer';
go
create user remdlguser2
without login;
go
--copy in the public cert from server 1 to somewhere on this server
--create a certificate from the public cert from server 1
create certificate DlgCertServ1Db1Pub
authorization remdlguser2
from file = 'c:\amit\Official\Service Broker\certs\2\DlgCertServ1Db1Pub.cer';
use [rem_ssb2];
go
-- we need two message types
CREATE MESSAGE TYPE [sendmsg]
VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE [recmsg]
VALIDATION = WELL_FORMED_XML;
go
--create the message contract
--and define who sends what
CREATE CONTRACT [Ctract]
(
[sendmsg]
sent by initiator,
[recmsg]
sent by target
);
go
--create the queue, at this stage we do not care
--about activation
CREATE QUEUE q2
with status = ON;
go
--we need a service
CREATE SERVICE [rem_s2]
on queue q2
(
[Ctract]
);
go
--create a route to the remote service, we know it'll be called rem_s1
create route [rem_s1_route]
with
service_name = 'rem_s1',
--broker_instance = 'D8EE8A81-F1B0-46B3-BBEB-70F19EF59083',
address = 'TCP://127.0.0.1:4021';
go
--as we'll be doing encrypted dialogs we need a remote service binding
--and the user is the user we created in the 2_setup_objects_server2_db.sql scripts
CREATE REMOTE SERVICE BINDING [myRms]
TO SERVICE 'rem_s1'
WITH USER = remdlguser2,
ANONYMOUS=Off
go
--give the user send rights on the service
grant send on service::rem_s2 to remdlguser2;
go
SELECT * from q2;
RECEIVER 2:
use [master];
go
--make sure master had master key
create master key encryption by password = 'masterhello2';
go
create certificate TrpCertServ3
with subject = 'Transport Certificate for Server3',
start_date = '06/01/2005';
go
--make sure the cert exist
select * from sys.certificates;
go
BACKUP CERTIFICATE TrpCertServ3
TO FILE = 'c:\amit\Official\Service Broker\certs\3\TrpCertServ3Pub.cer';
go
--you need to create an endpoint in order to enable communication
--outside of this instance
CREATE ENDPOINT SSB3
STATE = STARTED
AS TCP
(
LISTENER_PORT = 4023
)
FOR SERVICE_BROKER
(
AUTHENTICATION = CERTIFICATE TrpCertServ3,
ENCRYPTION = REQUIRED
);
go
--check that the endpoint has been created
select * from sys.endpoints;
go
--create a login and a user which you eventually will assign a public
--key from the cert in the remote master db to
create login remconnlogin3
with password = 'pass1234$';
go
create user remconnuser3
from login remconnlogin3;
go
--grant connect on the endpoint to the login
grant connect on endpoint::SSB3 to remconnlogin3
go
--copy in the public cert from server 1 to somewhere on this server
--create a certificate from the public cert from server 1
create certificate TrpCertServ1Pub
authorization remconnuser3
from file = 'c:\amit\Official\Service Broker\certs\3\TrpCertServ1Pub.cer';
use master;
go
--create the database
create database [rem_ssb3];
go
use [rem_ssb3];
go
--set master key
create master key
encryption by password = 'hellodb3';
go
create certificate DlgCertServ3Db3
with subject = 'DlgCertServ3Db3',
start_date = '06/01/2005'
active for begin_dialog = on;
go
--make sure the cert exist
select * from sys.certificates;
go
BACKUP CERTIFICATE DlgCertServ3Db3
TO FILE = 'c:\amit\Official\Service Broker\certs\3\DlgCertServ3Db3Pub.cer';
go
--create a user which you eventually will assign a public
--key from the cert in the remote db to
create user remdlguser3
without login;
go
--copy in the public cert from server 1 to somewhere on this server
--create a certificate from the public cert from server 1
create certificate DlgCertServ1Db1Pub
authorization remdlguser3
from file = 'c:\amit\Official\Service Broker\certs\3\DlgCertServ1Db1Pub.cer';
--create the message contract
--and define who sends what
CREATE CONTRACT [Ctract]
(
[sendmsg]
sent by initiator,
[recmsg]
sent by target
);
go
--create the queue, at this stage we do not care
--about activation
CREATE QUEUE q2
with status = ON;
go
--we need a service
CREATE SERVICE [rem_s2]
on queue q2
(
[Ctract]
);
go
--create a route to the remote service, we know it'll be called rem_s1
create route [rem_s1_route]
with
service_name = 'rem_s1',
--broker_instance = 'D8EE8A81-F1B0-46B3-BBEB-70F19EF59083',
address = 'TCP://127.0.0.1:4021';
go
--as we'll be doing encrypted dialogs we need a remote service binding
--and the user is the user we created in the 2_setup_objects_server2_db.sql scripts
CREATE REMOTE SERVICE BINDING [myRms]
TO SERVICE 'rem_s1'
WITH USER = remdlguser3,
ANONYMOUS=Off
go
--give the user send rights on the service
grant send on service::rem_s2 to remdlguser3;
go
select * from q2

