Havret / dotnet-activemq-artemis-client

.NET Client for Apache ActiveMQ Artemis
https://havret.github.io/dotnet-activemq-artemis-client/
MIT License
63 stars 11 forks source link

Support for ApplicationProperties, CloudNative.CloudEvents.Amqp #409

Closed JinsPeter closed 1 year ago

JinsPeter commented 1 year ago

Feature description

Feature in action

Provide a way to convert Amqp.Message to Artemis.Message. Now it only accepts BodySection. All metadata is lost. Also provide a way to recreate the cloudevent from the ArtemisMessage.


          CloudEvent cloudEvent = new CloudEvent(CloudEventsSpecVersion.V1_0)
            {
                Id = cloudEventId,
                Data = m_serializer.SerializeToJson(message),
                DataContentType = "application/json",
                Source = s_eventSource,
                Type = eventType,
                Time = DateTime.UtcNow,
            };

            Amqp.Message amqpMessage = cloudEvent.ToAmqpMessage(ContentMode.Structured, m_cloudEventFormatter);
            Message artemisMessage = new Message(amqpMessage.BodySection);

Describe alternatives you've considered

Additional context

CloudNative.CloudEvents.NetSDK - Please see Amqp.

Havret commented 1 year ago

Hi @JinsPeter,

To be honest, it's the first time I hear about CloudEvents, but the idea seems really nice and promising.

Regarding the implementation, I'm not so sure that exposing a method to transform ArtemisNetClient's message to AmqpNetLite's message would be the best way to tackle this issue. The fact that we are using AmqpNetLite internally is just an implementation detail, that may change in the future if any better, faster or more promising implementations of AMQP protocol appear in the dotnet landscape.

In my humble opinion, CloudEvents spec is simple enough so we could provide a full-blown integration[1] as an extension library to ArtemisNetClient.

CloudEvent cloudEvent = new CloudEvent(CloudEventsSpecVersion.V1_0)
{
    Id = cloudEventId,
    Data = m_serializer.SerializeToJson(message),
    DataContentType = "application/json",
    Source = s_eventSource,
    Type = eventType,
    Time = DateTime.UtcNow,
};

Message artemisMessage = cloudEvent.ToActiveMqMessage();

Would sth like that work for you?

I cannot promise a specific date, but I could try to implement it after Christmas.

Best, Havret

[1] Maybe we could use CloudNative.CloudEvents.Amqp under the hood to streamline the implementation.

Havret commented 1 year ago

Please check ArtemisNetClient.Extensions.CloudEvents 2.12.0-preview1.