Open AlbertoVPersonal opened 1 month ago
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?
This lib only implements the MQTT protocol and not some specific other specs.
You could create a separate lib which supports this functionality.
@AlbertoVPersonal why should the MQTTnet libary support the CloudEvents spec? This lib only implements the MQTT protocol and not some specific other specs. You could create a separate lib which supports this functionality.
Yes, I agree and I could create the lib because my internal code is ready to do it. Even I could develop a Nuget package but I cannot prioritize that task.
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!