Subscription endpoint not being called using Pub/Sub
See original GitHub issueTried a bare bones pub/sub sample with dapr 1.5.1 and the Subscribing endpoint is never called. Everything seems to be configured correctly and publishing works fine.
Program.cs looks like:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers().AddDapr();
var app = builder.Build();
//app.UseHttpsRedirection();
app.UseCloudEvents();
app.UseAuthorization();
app.MapControllers();
app.MapSubscribeHandler();
app.Run();
PublisherController.cs looks like:
using Dapr.Client;
using Microsoft.AspNetCore.Mvc;
namespace DaprPubSub.Controllers;
[ApiController]
public class PublisherController : ControllerBase
{
private readonly DaprClient _DaprClient;
private readonly ILogger<PublisherController> _logger;
public PublisherController(ILogger<PublisherController> logger, DaprClient daprClient)
{
_logger = logger;
_DaprClient = daprClient;
}
[HttpGet("publish")]
public async Task<IActionResult> PublishMessage([FromQuery] int s)
{
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;
var data = new MyEvent
{
Data = s
};
await _DaprClient.PublishEventAsync("pubsub", "my_topic", data, cancellationToken);
_logger.LogInformation($"Published message: {data.Data}");
return Ok(data);
}
}
SubscriberController.cs looks like:
using Microsoft.AspNetCore.Mvc;
using Dapr;
namespace DaprPubSub.Controllers;
[ApiController]
public class SubscriberController : ControllerBase
{
private readonly ILogger<SubscriberController> _logger;
public SubscriberController(ILogger<SubscriberController> logger)
{
_logger = logger;
}
[Topic("pubsub", "my_topic")]
[HttpPost("subscribe")]
public void HandleMessage([FromBody] MyEvent e)
{
_logger.LogInformation("Subscriber received : " + e.Data);
}
}
Calling /dapr/subscribe returns:
[{"topic":"my_topic","pubsubName":"pubsub","route":"subscribe"}]
And I can successfully publish from the /publish endpoint and the CLI. Additionally I can call the /subscribe endpoint directly with an HTTP Post so it’s not a routing issue.
Shouldn’t matter but I’m using the default pubsub.yaml with Redis.
Any ideas?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Gcp PubSub not pushing message to REST Endpoint
If it is a pubsub_interal_push error then most likely it is a certificate issue. Usually, Google doesn't accept URLs without HTTPS but in...
Read more >Troubleshoot Pub/Sub with the .NET SDK
The most common problem with pub/sub is that the pub/sub endpoint in your application is not being called. There are a few layers...
Read more >Troubleshooting | Cloud Pub/Sub Documentation
Learn about troubleshooting steps that you might find helpful if you run into problems using Pub/Sub. Cannot create a subscription.
Read more >Unable to receive pushed massages using pubsub
Hey Kir,. I did test the theory - creating a pull subscription then switching to a push subscription without doing any pull. and...
Read more >Using Cloud Pub/Sub as an endpoint for your app
Follow the Cloud Pub/Sub Subscriber Guide to set up a subscription to the topic that you created. Configure the subscription type to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey guys @conradcreel @bitTobiasMeier @halspang , I figured it out! I’m sure the ur using mac too, there is a Control Center process on Mac which is listening on 5000 prot. I call the /dapr/subscribe from postman when none of my apps running, I got a 403 code. So I’m sure there is some other process which is listening on 5000, so I run the command
lsof -i:5000
and got below informations The ControlCe process is listening on 5000! Then I change my app port to 6000 by runningdapr run --app-id sub-csharp --app-port 6000 -- dotnet run --urls=http://localhost:6000
and got no errors.Also some reference from Apple
I ran into a similar issue while trying to work through the Publish and Subscribe quickstart guide using the .NET samples. I am working on a Mac. Turns out it was a simple port configuration mismatch issue. The port in the quickstart documentation here doesn’t currently match the port in the code sample here
Updating the Dapr run --app-port argument to match the port the ASP.NET Core app is listening on fixed the issue. Suggest checking all of the port configurations in your setup.
Also, the Dapr documentation needs to be updated to match the code samples.