3

I am trying out Dapr for the first time ....refering to the Dapr go sdk at https://github.com/dapr/go-sdk...

... trying to host a Dapr service using golang with Docker Compose on my Windows 10 machine - using VSCode - and running into an issue connecting to ther service.

I have the docker compose file set to do a simple configuration as follows. And trying to connect to the service via the Dapr API using curl

golang service (taskapi service) => Dapr SideCar (taskapidapr)

I based it off of the example from https://github.com/dapr/go-sdk/blob/main/example/Makefile, but using Docker Compose.

When I try to connect connect to the service using

curl -d "ping" -H "Content-type: text/plain;charset=UTF-8" "http://localhost:8300/v1.0/invoke/taskapi/method/echo"

I am running into the following error.

{"errorCode":"ERR_DIRECT_INVOKE","message":"invoke API is not ready"}

And the Dapr logs in Docker show a 'no mDNS apps to refresh.' - not sure if this is the cause of it and how to handle it.

Anyone can point me to what I am missing - greatly appreciate it.

Thank you

  • Athadu

golang package

package main

import (
    "context"
    "errors"
    "fmt"
    "log"
    "net/http"

    "github.com/dapr/go-sdk/service/common"
    daprd "github.com/dapr/go-sdk/service/http"
)

func main() {

    port := "8085"
    address := fmt.Sprintf(":%s", port)

    log.Printf("Creating New service at %v port", address)
    log.Println()

    // create a Dapr service (e.g. ":8080", "0.0.0.0:8080", "10.1.1.1:8080" )
    s := daprd.NewService(address)

    // add a service to service invocation handler
    if err := s.AddServiceInvocationHandler("/echo", echoHandler); err != nil {
        log.Fatalf("error adding invocation handler: %v", err)
    }

    if err := s.Start(); err != nil && err != http.ErrServerClosed {
        log.Fatalf("error listenning: %v", err)
    }
}

func echoHandler(ctx context.Context, in *common.InvocationEvent) (out *common.Content, err error) {
    if in == nil {
        err = errors.New("invocation parameter required")
        return
    }
    log.Printf(
        "echo - ContentType:%s, Verb:%s, QueryString:%s, %s",
        in.ContentType, in.Verb, in.QueryString, in.Data,
    )
    out = &common.Content{
        Data:        in.Data,
        ContentType: in.ContentType,
        DataTypeURL: in.DataTypeURL,
    }
    return
}

docker-compose.yml

version: "3"

services:
    taskapi:
        image: golang:1.16
        volumes:
            - ..:/go/src/lekha
        working_dir: /go/src/lekha/uploader
        command: go run main.go
        ports: 
            - "8085:8085"
        environment:
            aaa: 80
            my: I am THE variable value
        networks:
            - lekha
    taskapidapr:
        image: "daprio/daprd:edge"
        command: [
            "./daprd",
            "-app-id", "taskapi",
            "-app-protocol", "http",
            "-app-port", "8085",
            "-dapr-http-port", "8300",
            "-placement-host-address", "placement:50006",
            "-log-level", "debug",
            "-components-path", "/components"
        ]
        volumes:
            - "../dapr-components/:/components" # Mount our components folder for the dapr runtime to use
        depends_on:
            - taskapi
        ports: 
           - "8300:8300"
        networks:
           - lekha
        #network_mode: "service:taskapi" # Attach the task-api-dapr service to the task-api network namespace
    ############################
    # Dapr placement service
    ############################
    placement:
        image: "daprio/dapr"
        command: ["./placement", "-port", "50006"]
        ports:
            - "50006:50006"
        networks:
            - lekha
networks:
    lekha:
        

Docker Container List

Inspecting the network in Docker shows the containers to be in the same network

Daprd shows these mDNS messages in logs - not sure if this is the cause

time="2021-05-24T01:06:13.6629303Z" level=debug msg="Refreshing all mDNS addresses." app_id=taskapi instance=442e04c9e8a6 scope=dapr.contrib type=log ver=edge

time="2021-05-24T01:06:13.6630421Z" level=debug msg="no mDNS apps to refresh." app_id=taskapi instance=442e04c9e8a6 scope=dapr.contrib

Additionally, I see the containers on the expected ports ... running fine in Docker desktop...

enter image description here

enter image description here

2
  • I'm experiencing the same issue, were you able to find a solution for it? Commented Jul 22, 2021 at 16:24
  • I'm getting the same . I can't do service to service invocation. Dapr state is working though. Commented Jul 14, 2023 at 9:46

1 Answer 1

-1

enter image description here

{
"errorCode": "ERR_DIRECT_INVOKE",
"message": "invoke API is not ready"

}

same as yours

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.