Set up C# client
To set up C# client library in Pulsar, complete the following steps.
Step 1: Install C# client library
This section describes how to install the Pulsar C# client library through the dotnet CLI.
Alternatively, you can install the Pulsar C# client library through Visual Studio. Note that starting from Visual Studio 2017, the dotnet CLI is automatically installed with any .NET Core related workloads. For more information, see Microsoft documentation.
To install the Pulsar C# client library using the dotnet CLI, follow these steps:
-
Install the .NET Core SDK, which provides the dotnet CLI.
-
Create a project.
-
Create a folder for the project.
-
Open a terminal window and switch to the new folder.
-
Create the project using the following command.
dotnet new console
-
Use
dotnet run
to test that the app has been created properly.
-
-
Add the DotPulsar NuGet package.
-
Use the following command to install the
DotPulsar
package.dotnet add package DotPulsar
-
After the command completes, open the
.csproj
file to see the added reference.<ItemGroup>
<PackageReference Include="DotPulsar" Version="2.0.1" />
</ItemGroup>
-
Step 2: Connect to Pulsar cluster
To connect to Pulsar using client libraries, you need to specify a Pulsar protocol URL.
You can assign Pulsar protocol URLs to specific clusters and use the pulsar
scheme. The following is an example of localhost
with the default port 6650
:
pulsar://localhost:6650
If you have multiple brokers, separate IP:port
by commas:
pulsar://localhost:6550,localhost:6651,localhost:6652
If you use mTLS authentication, add +ssl
in the scheme:
pulsar+ssl://pulsar.us-west.example.com:6651