Skip to content

Demo on how to Use the gRPC interface in your Dapr app

Notifications You must be signed in to change notification settings

abelhoula/dpar-gRPC-interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dpar gRPC interface

Requiremets

Overview

Service Invocation in Dapr: Simplifying Cross-Application Communication

Dapr's service invocation feature enhances cross-application communication by providing seamless methods to call functions between microservices applications or external HTTP endpoints.

  • HTTP Service Invocation: If your application already utilizes HTTP protocols, incorporating Dapr is straightforward. Simply include the Dapr HTTP header, dapr-app-id, without the need to alter existing endpoint URLs. This allows you to quickly integrate service invocation capabilities. For detailed information, refer to Invoke Services using HTTP.

  • gRPC Service Invocation: Dapr seamlessly integrates with gRPC, allowing users to interact with their existing proto services without the need for additional Dapr SDKs or custom gRPC services. Explore the step-by-step guide in the Dapr and gRPC tutorial for more details.

Description

The provided Go code implements a Dapr application featuring service gRPC invocation capabilities. The key functionalities include:

  • Method Invocation: The application defines a method, EchoMethod, which responds with "pong" when invoked. This serves as a basic demonstration of remote method invocation.

  • Event Handling: The code includes methods, such as OnBindingEvent and OnTopicEvent, to handle events triggered by registered bindings and subscribed topics.

  • List Topic Subscriptions: The ListTopicSubscriptions method specifies the application's interest in subscribing to a topic named "TopicA."

In summary, Dapr supports native interaction with gRPC, allowing users to maintain their own proto services effortlessly. This enables the invocation of existing gRPC applications without requiring additional Dapr SDKs or custom gRPC services. Explore the Dapr and gRPC tutorial for a step-by-step guide.

Initialize dapr

Dapr runs as a sidecar alongside your application. In self-hosted mode, this means it is a process on your local machine. By initializing Dapr, you:

Fetch and install the Dapr sidecar binaries locally. Create a development environment that streamlines application development with Dapr.

  1. Make sur that docker is runing & Run the init CLI command
    dapr init
    
  2. Verify containers are running
    docker ps
    

Testing

  1. Run the application
    dapr run --app-id gosvc --app-port 50001 --app-protocol grpc go run main.go
    
  2. Invoke the App:
    dapr invoke --app-id gosvc --method EchoMethod
    
    This should return pong as defined in your EchoMethod
  3. Test Bindings and Topics (Optional)
    • publish a message to a topicA
      dapr publish --publish-app-id gosvc --pubsub pubsub --topic TopicA --data "Hello, Dapr!"
      

About

Demo on how to Use the gRPC interface in your Dapr app

Topics

Resources

Stars

Watchers

Forks

Languages