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

[Topic] Attribute doesn't support dynamic routes #1130

Open
fabistb opened this issue Aug 1, 2023 · 4 comments
Open

[Topic] Attribute doesn't support dynamic routes #1130

fabistb opened this issue Aug 1, 2023 · 4 comments
Labels
area/aspnetcore Issues for aspnetcore integration with Dapr. question Further information is requested

Comments

@fabistb
Copy link

fabistb commented Aug 1, 2023

Currently the [Topic] cant be used if the route contains a dynamic part.
A example here is a version in the route.

Example dynamic route:

[ApiController]
[ApiVersion("1.0")]
[Route("api/v{v:apiVersion}/example]
public class ExampleController : ControllerBase
{
  [HttpPost()]
  [Topic("messagebus", "topic")
  public async Task<IActionResult> PubSub([FromBody] object message)
  {
  ...
  }
}

Example static route:

[ApiController]
[Route("api/v1.0/example]
public class ExampleController : ControllerBase
{
  [HttpPost()]
  [Topic("messagebus", "topic")
  public async Task<IActionResult> PubSub([FromBody] object message)
  {
  ...
  }
}

Is their a specific reason why the dynamic routes aren't supported?

@halspang halspang added question Further information is requested area/aspnetcore Issues for aspnetcore integration with Dapr. labels Aug 17, 2023
@halspang
Copy link
Contributor

As far as I'm aware, there is no direct reason for it not working. We just parse the attributes and add them to an endpoint collection.

I'm not super familiar with this space though, does this work for other attributes that are nested like this? I'm worried the reason it wouldn't work is because we're taking the literal and don't have the information to interpret the path when we read the attributes.

@fabistb
Copy link
Author

fabistb commented Sep 11, 2023

Thanks for the explanation.

Not sure here since I also can't think about an attribute currently which is as nested as this one.

@philliphoff
Copy link
Collaborator

It looks like the Dapr route building logic doesn't support routes with parameters (i.e. the logic assumes the parts are all literals):

.Select(segment => string.Concat(segment.Parts.Cast<RoutePatternLiteralPart>()

As @halspang suggests, we'd need to investigate whether we can get the resolved values out of ASP.NET in order to build the route strings.

@philliphoff
Copy link
Collaborator

I believe this is the same issue as #791 and #882. As was mentioned in those issues, there is a fundamental question of how Dapr subscriptions should work in a multi-versioned API (the likely reason for having dynamic routes). For example, if two controllers representing two versions of the same API have the same topics (i.e. what's the likelihood of these changing between API versions), how should messages be delivered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/aspnetcore Issues for aspnetcore integration with Dapr. question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants