-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support to CloudEvents v1.0 #2092
Comments
not sure what you mean by "supports CloudEvent spec". I've been prototyping basic support by adding an extension method to populate the required message properties: public class CloudEvent(Uri source, string type = "ms.aio.telemetry", string specversion = "1.0")
{
private string? _id = null!;
public Uri? Source { get => source; }
public string SpecVersion { get => specversion; }
public string Type { get => type; }
public string? Id { get => _id; internal set => _id = value; } // although id is required, we want update it in the same instance from the sender.
// optional
private string? _dataContentType;
private string? _dataSchema;
private string? _subject;
private DateTime? _time;
public DateTime? Time { get => _time; internal set => _time = value; }
public string? DataContentType { get => _dataContentType; internal set => _dataContentType = value; }
public string? Subject { get => _subject; internal set => _subject = value; }
public string? DataSchema { get => _dataSchema; set => _dataSchema = value; }
}
public static partial class MqttApplicationMessageBuilderExtension
{
public static MqttApplicationMessageBuilder WithCloudEvents(this MqttApplicationMessageBuilder mb, CloudEvent md)
{
mb.WithUserProperty(nameof(md.SpecVersion).ToLowerInvariant(), md.SpecVersion)
.WithUserProperty(nameof(md.Id).ToLowerInvariant(), md.Id!.ToString())
.WithUserProperty(nameof(md.Type).ToLowerInvariant(), md.Type)
.WithUserProperty(nameof(md.Source).ToLowerInvariant(), md.Source!.ToString());
if (md.Time is not null)
{
mb.WithUserProperty(nameof(md.Time).ToLowerInvariant(), md.Time!.Value.ToString("O"));
}
if (md.Subject is not null)
{
mb.WithUserProperty(nameof(md.Subject).ToLowerInvariant(), md.Subject);
}
if (md.DataContentType is not null)
{
mb.WithUserProperty(nameof(md.DataContentType).ToLowerInvariant(), md.DataContentType);
}
if (md.DataSchema is not null)
{
mb.WithUserProperty(nameof(md.DataSchema).ToLowerInvariant(), md.DataSchema);
}
return mb;
}
} |
I mean you are prototyping but embed on the own library as a standard feature. |
@AlbertoVPersonal why should the MQTTnet libary support the CloudEvents spec? |
Yes, I agree and I could create the lib because my internal code is ready to do it. Anyway, I think that it would be a plus because:
|
Hi,
Does someone know whether MQTTnet supports the CloudEvents spec?
I'm using MQTTnet in my project. Also I'm using an external runtime that it supports CloudEvents and I would like to analyze a feature that this runtime has.
Regards!
The text was updated successfully, but these errors were encountered: