EasyCore.Pulsar
8.0.0
See the version list below for details.
dotnet add package EasyCore.Pulsar --version 8.0.0
NuGet\Install-Package EasyCore.Pulsar -Version 8.0.0
<PackageReference Include="EasyCore.Pulsar" Version="8.0.0" />
<PackageVersion Include="EasyCore.Pulsar" Version="8.0.0" />
<PackageReference Include="EasyCore.Pulsar" />
paket add EasyCore.Pulsar --version 8.0.0
#r "nuget: EasyCore.Pulsar, 8.0.0"
#:package EasyCore.Pulsar@8.0.0
#addin nuget:?package=EasyCore.Pulsar&version=8.0.0
#tool nuget:?package=EasyCore.Pulsar&version=8.0.0
β‘ EasyCore.Pulsar
EasyCore.Pulsar is an Apache Pulsar infrastructure client for .NET 8. Built on Pulsar.Client, it provides DI registration, connect, topic publish/subscribe, and
AcknowledgeAsync. It is not tied toIEvent/ EventBus β use it standalone, or via theEasyCore.EventBus.Pulsaradapter.
π Language
- Chinese: README.md
- English (this document)
π Table of Contents
- 1. Positioning
- 2. Relation to EventBus
- 3. Requirements
- 4. Installation
- 5. Quick Start
- 6. API Overview
- 7. Options (
PulsarOptions) - 8. FAQ
- 9. License
1. π― Positioning
| Scenario | Fit? |
|---|---|
| Byte-level publish/subscribe on Pulsar topics | β |
| Properties and MessageId acknowledgment | β |
| TLS / authentication client options | β |
Unified IEvent + handler discovery (EDA) |
β β use EasyCore.EventBus.Pulsar |
| In-process local events | β β use EasyCore.EventBus local bus |
1.1 Design Principles
| Principle | Meaning |
|---|---|
| Infrastructure layer | ServiceUrl, topic prefix, TLS, and raw bytes |
| Standalone | No dependency on the EasyCore.EventBus core package |
| Adapter-friendly | The EventBus Pulsar adapter reuses this client |
2. Relation to EventBus
βββββββββββββββββββββββββββββββ
β App code (any payload) β
ββββββββββββββββ¬βββββββββββββββ
β IPulsarClient
βΌ
βββββββββββββββββββββββββββββββ
β EasyCore.Pulsar (this) β β infrastructure client
ββββββββββββββββ¬βββββββββββββββ
β Pulsar.Client
βΌ
Pulsar Cluster
βββββββββββββββββββββββββββββββ
β EasyCore.EventBus.Pulsar β β adapter: IEvent / Handler
β βββ uses this client β
βββββββββββββββββββββββββββββββ
| Package | Role |
|---|---|
EasyCore.Pulsar |
Generic Pulsar client (this package) |
EasyCore.EventBus.Pulsar |
Maps EventBus IEvent onto Pulsar |
3. β Requirements
| Item | Requirement |
|---|---|
| .NET | 8.0+ |
| Dependency | Pulsar.Client 3.12.x (brought by this package) |
| Broker | Reachable Pulsar service URL (e.g. pulsar://localhost:6650) |
4. π₯ Installation
dotnet add package EasyCore.Pulsar
5. β‘ Quick Start
5οΈβ£.1οΈβ£ Register DI
using EasyCore.Pulsar;
builder.Services.EasyCorePulsar(o =>
{
o.ServiceUrl = "pulsar://localhost:6650";
o.TopicPrefix = "persistent://public/default/";
o.AppName = "MyApp";
// TLS / auth as needed:
// o.UseTls = true;
// o.TlsAllowInsecureConnection = false;
});
5οΈβ£.2οΈβ£ Publish
public sealed class InvoicePublisher
{
private readonly IPulsarClient _client;
public InvoicePublisher(IPulsarClient client) => _client = client;
public async Task PublishAsync(string invoiceId, CancellationToken ct = default)
{
await _client.ConnectAsync(ct);
var body = Encoding.UTF8.GetBytes($$"""{"invoiceId":"{{invoiceId}}"}""");
var properties = new Dictionary<string, string>
{
["EventType"] = "InvoiceCreated"
};
// Relative topic names are prefixed with TopicPrefix
await _client.PublishAsync(
topic: "invoice.created",
body: body,
properties: properties,
cancellationToken: ct);
}
}
5οΈβ£.3οΈβ£ Subscribe and Acknowledge
public sealed class InvoiceConsumer : BackgroundService
{
private readonly IPulsarClient _client;
public InvoiceConsumer(IPulsarClient client) => _client = client;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _client.ConnectAsync(stoppingToken);
await _client.SubscribeAsync(
topics: new[] { "invoice.created" },
handler: async (msg, ct) =>
{
var json = Encoding.UTF8.GetString(msg.Body.Span);
// handle businessβ¦
await _client.AcknowledgeAsync(msg.MessageId, ct);
},
cancellationToken: stoppingToken);
}
}
PulsarDeliveredMessage fields: Topic, Body, Properties, MessageId.
6. π§© API Overview
| Member | Description |
|---|---|
EasyCorePulsar(Action<PulsarOptions>) |
DI: Options and IPulsarClient |
ConnectAsync |
Connect to ServiceUrl and build the native client |
PublishAsync(topic, body, properties?) |
Publish; relative topics get TopicPrefix |
SubscribeAsync(topics, handler) |
Subscribe and start a background consume loop |
AcknowledgeAsync(messageId) |
Acknowledge by Pulsar MessageId |
IPulsarClient implements IAsyncDisposable β dispose on shutdown.
7. Options (PulsarOptions)
| Property | Type | Default | Description |
|---|---|---|---|
ServiceUrl |
string |
pulsar://localhost:6650 |
Pulsar service URL |
EnableClientLog |
bool |
false |
Enable native client logging |
UseTls |
bool |
library default | Enable TLS |
TlsHostnameVerificationEnable |
bool |
library default | TLS hostname verification |
TlsAllowInsecureConnection |
bool |
library default | Allow insecure TLS |
TlsTrustCertificate |
X509Certificate2 |
library default | Trust certificate |
Authentication |
Authentication |
library default | Pulsar auth plugin/config |
TlsProtocols |
SslProtocols |
library default | Allowed TLS protocols |
TopicPrefix |
string |
persistent://public/default/ |
Prefix for relative topic names |
AppName |
string? |
null |
Subscription/consumer naming; entry assembly when null |
TLS / Authentication defaults come from
PulsarClientConfiguration.Default.
8. β FAQ
Q: This package vs EasyCore.EventBus.Pulsar?
A: Use the EventBus adapter for IEvent, handlers, and retries. Use this package for raw topic I/O.
Q: Must topics be fully qualified?
A: Relative names are fine (prefixed with TopicPrefix), or use full persistent://tenant/ns/topic.
Q: Must I call ConnectAsync first?
A: Yes β connect before publish or subscribe so the native client is built.
Q: How do I enable TLS?
A: Set UseTls = true and configure certificates, hostname verification, and Authentication as needed.
9. π License
MIT OR Apache-2.0 β see the repository LICENSE if present, or the NuGet package metadata.
π€ Contributing
Issues and PRs are welcome. After changing this package, verify EasyCore.EventBus.Pulsar and related demos.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Pulsar.Client (>= 3.12.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on EasyCore.Pulsar:
| Package | Downloads |
|---|---|
|
EasyCore.EventBus.Pulsar
.NET Core EventBus distributed transport based on Pulsar. |
GitHub repositories
This package is not used by any popular GitHub repositories.