C# .NET is in development for v1. Interested in contributing or chatting with us?Get in touch!
.NET - Topic.Publish()
Publish an event (push based message) to a topic.
using Nitric.Sdk;
using Nitric.Sdk.Resource;
using Nitric.Sdk.Event;
class EventUpdate
{
public string Message { get; set; }
}
var updates = Nitric.Topic<EventUpdate>("updates").With(TopicPermission.Publishing);
updates.Publish(new EventUpdate { Message = "payload sent" });
Nitric.Run();
Parameters
- Name
event
- Required
- Required
- Type
- Event<T>
- Description
The event to publish to the topic
- Name
Id
- Optional
- Optional
- Type
- string
- Description
unique id to apply to the event.
- Name
Payload
- Required
- Required
- Type
- T
- Description
payload to send with the event.
- Name
PayloadType
- Optional
- Optional
- Type
- string
- Description
a hint to the type of payload supplied.
Examples
Publish a topic
using Nitric.Sdk;
using Nitric.Sdk.Event;
using Nitric.Sdk.Resource;
class EventUpdate
{
public string Message { get; set;}
}
var updates = Nitric.Topic<EventUpdate>("updates").With(TopicPermission.Publishing);
updates.Publish(new Event<EventUpdate>
{
Id = "1234",
PayloadType = "event_udpate",
Payload = new EventUpdate
{
Message = "event has been updated"
}
}
);
Nitric.Run();
Notes
- If an id is not supplied with an event a UUID(v4) will be generated for you.
- A function may subscribe to OR publish to a topic but not both.