Dapr pubsub 订阅者未收到消息

问题描述 投票:0回答:1

我已经在本地实现了带有事件中心的 Dapr PubSub。 我已将 Dapr 配置添加到这两个项目中。 从发布者 daprclient.PublishEventAsync 被调用,并使用 pubsubname 和 topicname

执行

但是,在订阅者应用程序中,我订阅了相同的主题,但没有收到任何消息。

出版商

    [HttpPost]
    public async Task<IActionResult> WeatherChange([FromBody] WeatherChange weatherChange)
    {
        var source = new CancellationTokenSource();
        var cancellationToken = source.Token;
        _logger.LogInformation("Customer Order received: {@WeatherChange}", weatherChange);

        try
        {
            await _daprClient.PublishEventAsync(Constants.PubSubName, "myeventhub", weatherChange, cancellationToken);
            _logger.LogInformation("Published message: {weatherChange} ", weatherChange);
        }
        catch (Exception e)
        {
            return BadRequest("Please try again");
        }

        return Ok("Weather Change Published");

订阅者

  [Topic(Constants.PubSubName, "myeventhub")]
    [HttpPost("/weather")]
    public void PostWeathers(WeatherChange weather)
    {
        _logger.LogInformation("Weather posted in subscribed............... {WeatherChange}", weather);
       
    }

在启动时还添加了 Dapr 配置

 public void ConfigureServices(IServiceCollection services)
        {

            services.AddControllers().AddDapr();
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "Dapr.SubscriberService", Version = "v1" });
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Dapr.SubscriberService v1"));
            }
           
            app.UseRouting();

            app.UseAuthorization();

            // Use Cloud Events
            app.UseCloudEvents();

            app.UseEndpoints(endpoints =>
            {
                // Map subscriber handler
                endpoints.MapSubscribeHandler();

                endpoints.MapControllers();

            });
        }

我有预期的组件文件。

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.azure.eventhubs
  version: v1
  metadata:
    # Either connectionString or eventHubNamespace is required
    # Use connectionString when *not* using Azure AD
    - name: connectionString
      value: "<Removed>"
    # Use eventHubNamespace when using Azure AD
    - name: enableEntityManagement
      value: "false"
    # The following four properties are needed only if enableEntityManagement is set to true
    - name: resourceGroupName
      value: "<Removed>"
    - name: subscriptionID
      value: "<Removed>"
    - name: partitionCount
      value: "1"
    - name: messageRetentionInDays
      value: "3"
    # Checkpoint store attributes
    - name: storageAccountName
      value: "<Removed>"
    - name: storageAccountKey
      value: "<Removed>"
    - name: storageContainerName
      value: "<Removed>"
    # Alternative to passing storageAccountKey
    - name: storageConnectionString
      value: "<Removed>"
scopes:
  - publisher-service
  - subscriber-service

以下是我用于订阅者的命令

dapr run --app-id subscriber-service --resources-path components --app-port 5200 --dapr-grpc-port 5201 --dapr-http-port 5280

非常感谢任何帮助!

asp.net-core .net-core publish-subscribe azure-eventhub dapr
1个回答
0
投票

我也有同样的问题。删除 app.UseHttpsRedirection();在program.cs中使其工作。Se代码在这里Github ApireDaprPubSubDemo

© www.soinside.com 2019 - 2024. All rights reserved.