Git Product home page Git Product logo

dapr-publish-subscribe's Introduction

DAPR: publish and subscribe messages example

Example: Distributed Application Runtime(DAPR) Publish and Subscriber messages

  • Using .NET7
  • Using RabbitMQ on local
  • Using Container App, Dapr Component and AzureServiceBus in Azure
  • CI/CD: GitHub Action

Requirements


  • Install Dapr
  • Install .NET7

Structures


  • Producer: using the API sends messages
  • Consumer: receive messages from pubSubName and Topic
  • Messages: create message model
  • ComponentsLocal: pubsub.yaml is config your message bus (RabbitMQ)
  • Components: pubsub.yaml is config your message bus (Azure Service Bus)

Usages

  • Start RabbitMQ:

    cd DemoMicroservices
    docker-compose up
    
  • Using RabbitMQ: Set PubSubName="order-pub-sub"

  • Start Consumer(app-id: checkout)

    cd DemoMicroservices\Consumer
    dapr run --app-id checkout --components-path ../../ComponentsLocal --app-port 5000 --dapr-http-port 3500 --dapr-grpc-port 60002 dotnet run
    

    The /checkout endpoint matches the route defined in the subscriptions and this is where Dapr will send all topic messages to. It will be created a queue with name: checkout-orders

  • Start Producer(app-id: orderprocessing)

    cd DemoMicroservices\Producer
    dapr run --app-id orderprocessing --app-port 5011 --dapr-http-port 3501 --dapr-grpc-port 60001 --components-path ../../ComponentsLocal dotnet run
    
  • Send a message from Producer to Consumer

    http://localhost:5011/order
    {
        "OrderAmount":12.7,
        "OrderNumber":"Num18291",
        "OrderDate":"2021-12-21"
    }
    

Using Azure Container App and Azure Service Bus

  • Create Azure Credential

    az ad sp create-for-rbac --name "myApp" --role contributor \
        --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
        --sdk-auth
    
  • Create Dapr Component

    • $ENVIRONMENT: Container App Environment
    az containerapp env dapr-component set \
        --name $ENVIRONMENT --resource-group $RESOURCE_GROUP \
        --dapr-component-name order-pub-sub \
        --yaml '.\Components\pubsub.yaml'
    
  • Enable Ingress in Producer Container

    az containerapp ingress enable --name producer-container  \
        --resource-group containers --target-port 80 --exposed-port 80 \
        --transport http --type external --allow-insecure
    

Result

  • Publish message Publisher

  • Consumer message Consumer

  • Consumer Container Config in Azure Consumer Container Config

  • Producer Container Config in Azure Producer Container Config

  • Add Dapr Component in Azure Dapr Component

  • Producer Logging in Azure Producer Logging

  • Consumer Container Logging in Azure Consumer Container

References


dapr-publish-subscribe's People

Contributors

nhatthaiquang-agilityio avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

magic5644

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.