Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using rabbitmq as broker in service , fail to publish mq message with " service not found" #2695

Closed
szhengli opened this issue Mar 12, 2024 · 1 comment

Comments

@szhengli
Copy link

szhengli commented Mar 12, 2024

fail to publish mq, with the "service not found".
can anyone help ? thank you.


package main

import (
"context"
"fmt"
mq "github.com/go-micro/plugins/v4/broker/rabbitmq"
"github.com/go-micro/plugins/v4/registry/etcd"
"log"
"time"

"go-micro.dev/v4"
"go-micro.dev/v4/broker"
registry "go-micro.dev/v4/registry"

)

var (
topic = "go.micro.topic.foo"
)

type Request struct {
Name string json:"name"
}

type Response struct {
Message string json:"message"
}

type Helloworld struct{}

func (h *Helloworld) Greeting(ctx context.Context, req *Request, rsp *Response) error {
rsp.Message = "Hello " + req.Name
fmt.Println("!!!!!!!!!!!!!")

msg := &broker.Message{
	Header: map[string]string{
		"id": fmt.Sprintf("%d", 1),
	},
	Body: []byte(fmt.Sprintf("%d: %s", 1, time.Now().String())),
}
if err := broker.Publish(topic, msg); err != nil {
	log.Printf("[pub] failed: %v", err)
} else {
	fmt.Println("[pub] pubbed message:", string(msg.Body))
}
fmt.Println("!!!!!!!!!!!!!")
return nil

}

func main() {

edcdRegistry := etcd.NewRegistry(registry.Addrs("192.168.2.89:2379"))
mqbroker := mq.NewBroker(broker.Addrs("amqp://guest:[email protected]:5672/"))

service := micro.NewService(
	micro.Name("helloworld"),
	micro.Handle(new(Helloworld)),
	micro.Address(":8080"),
	micro.Registry(edcdRegistry),
)
service.Init(micro.Broker(mqbroker))


service.Run()

}

@asim
Copy link
Member

asim commented Jul 12, 2024

Please fix the formatting off your code. It's unreadable. You are using an etcd registry and rabbitmq. Both publisher and consumer will need to be using the same configuration.

@asim asim closed this as completed Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants