Change Service Broker Port: Drop and Recreate the Endpoint

To change Service Broker port, drop the old endpoint and create a new one on another port. This post follows my introduction to Service Broker and my post on error 9692.

Diagram of two SQL Server instances, each with a Service Broker holding Message, Contract and Service, joined by a dialog conversation; the two BrokerEndpoint boxes talk over TCP and the LISTENER_PORT value 5000 is marked in red

Why Change the Port

Two days ago I wrote a short note, Introduction to Service Broker. Yesterday I wrote about error 9692. There, Service Broker threw an error because another application used the same port.

One option was to configure Service Broker on a port that the other application does not use. I got a couple of requests to show how to do that, so here it is.

Script 1: Create the Service Broker Endpoint

This script creates the endpoint on a specific port, with the authentication Service Broker needs. The example uses port 5000.

USE master;
GO
CREATE ENDPOINT BrokerEndpoint
STATE = STARTED
AS TCP ( LISTENER_PORT = 5000)
FOR SERVICE_BROKER ( AUTHENTICATION = WINDOWS );
GO

Script 2: Drop the Service Broker Endpoint

This script drops the endpoint. Together, the two scripts move Service Broker to a different port. Drop the old endpoint, then create it again on the new port.

USE master ;
GO
DROP ENDPOINT BrokerEndpoint ;
GO

Do you know a way to change the port without dropping and creating the endpoint? Please share your method in the comments.

What Service Broker Is Built For

Service Broker is designed around the basic functions of sending and receiving messages. Each message forms part of a conversation, and each conversation is a reliable, persistent communication channel. Each message and conversation has a specific type, which helps developers write reliable applications.

The framework gives you a simple Transact-SQL interface for sending and receiving messages. It comes with strong guarantees for message delivery and processing. A program receives each message in a conversation exactly once. Messages arrive in the order they were sent, not the order they entered the queue.

Quick reference card: change the Service Broker port

A port clash is not a broken Service Broker, it is two programs claiming one port.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Service Broker, SQL Scripts, SQL Server
Previous Post
SQL Server – Fix – Error : 9692 The _MSG protocol transport cannot listen on port because it is in use by another process.
Next Post
SQL SERVER – FIX – ERROR : 9004 An error occurred while processing the log for database. If possible, restore from backup. If a backup is not available, it might be necessary to rebuild the log.

Related Posts

3 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.