Skip to content
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

Add support for subscribing to raw messages #709

Closed
sapinderpalsingh opened this issue Jul 5, 2021 · 6 comments
Closed

Add support for subscribing to raw messages #709

sapinderpalsingh opened this issue Jul 5, 2021 · 6 comments
Assignees

Comments

@sapinderpalsingh
Copy link
Contributor

sapinderpalsingh commented Jul 5, 2021

Describe the proposal

Dapr 1.2 supports subscribing to raw messages which are non cloud events. We can either change the current MapSubscribeHandler by adding a boolean flag to it or we can create a new extension method to support subscribing to raw messages.
Also third option is configuring it at the topic level by adding one more boolean argument for processing raw messages, which can provide more flexibility where we can have one topic configured for cloud events and other for raw messages.

[Topic("pubsub", "topic",true)]
[HttpPost("onEvent")]
public async Task<IActionResult> OnEvent([FromBody] Event data)
{
}

Currently i have created a separate extension method to support this in our recent client engagement.

@tanvigour
Copy link

@rynowak Any thoughts on this?

@rynowak
Copy link
Contributor

rynowak commented Jul 13, 2021

Hi @sapinderpalsingh

We'd be happy to accept a PR that adds one or both of these options.

We can either change the current MapSubscribeHandler by adding a boolean flag to it or we can create a new extension method to support subscribing to raw messages.

I would suggest adding a new overload that takes an options class. This is preferrable to a boolean argument for scannability and makes it easy to add other settings in the future without changing the signature. Something like:

public static IEndpointConventionBuilder MapSubscribeHandler(this IEndpointRouteBuilder endpoints, SubscribeOptions options)
{
}

public class SubscribeOptions
{
    public bool EnableRawPayload { get; set; }
}

Also third option is configuring it at the topic level by adding one more boolean argument for processing raw messages, which can provide more flexibility where we can have one topic configured for cloud events and other for raw messages.

It seems really useful to have both of these options. You have the ability to configure globally, as well as per-topic for the app.

I'd suggest something like:

public class TopicAttribute : Attribute, ITopicMetadata, IRawTopicMetadata
{
    ...

    public bool? EnableRawPayload { get; set; }
}

public interface IRawTopicMetadata
{
    bool? EnableRawPayload { get; set; }
}

The extra interface is needed because we can't add properties to ITopicMetadata without a breaking change.

The attribute uses bool? because that allows you to implement three valued logic:

  • true => override global setting with true
  • false => override global setting with false
  • null => use global setting

@codeputer
Copy link

codeputer commented Jul 13, 2021 via email

@sapinderpalsingh
Copy link
Contributor Author

Thanks @rynowak , I am working on this and will update you once I submit the PR.

@rynowak
Copy link
Contributor

rynowak commented Aug 12, 2021

@codeputer - it sounds like you're talking about something completely different from this issue. I'd suggest opening a new issue and using that to discuss.

@mpprasanth
Copy link

@rynowak @sapinderpalsingh I have posted an issue here #989
Can you please help ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants