0

I have implemented Dapr PubSub with Event Hubs Locally. I have added Dapr Configurations to both the projects. From publisher daprclient.PublishEventAsync is called and that is executed with the pubsubname and topicname

However, in the subscriber application i have subscribed to same topic but not receiving any messages.

Publisher

    [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");

Subscriber

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

In startup also added Dapr configuration

 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();

            });
        }

I have my component file as expected.

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

below are the commands that i am using for subscriber

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

Any help much appreciated!

0 Answers0