mq/

directory
v0.0.0-...-26e1b9e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: Apache-2.0

README

MQ模块

MQ模块封装了Kafka和RabbitMQ的库的功能。

使用示例:

func TestConsumer_Handle(t *testing.T) {
	consumer := NewConsumer(&Config{
		Host:      "dev.rabbitmq.yaoxinhd.io",
		UserName:  "kyoto",
		Password:  "qWAbkZZqzhm/6666+xnBuQ9JHeSnYH4cb3uppHO+BhU=",
		Port:      5672,
		Vhost:     "kyoto",
		QueueName: "queue.lps-service.applyQueue1",
		//Exchange: "exchange.direct.lps-service",
		//ExchangeType: "direct",
		//RoutingKey: "key.lps-service.applyQueue1",
		Tag: "kuat",
	})

	err := consumer.Connect()
	fmt.Println(err)
	consumer.Handle(handle, 1)
	time.Sleep(time.Minute)
}

type Receive struct {
	MsgId   string `json:"msgId"`
	Content map[string]interface{}
}

func handle(deliveries <-chan amqp.Delivery) {
	fmt.Println("000000")
	for d := range deliveries {
		fmt.Println("000000")
		var data Receive
		////json.Unmarshal(d.Body, &data)

		fmt.Println(d.Body)
		json.Unmarshal(d.Body, &data)
		fmt.Println(data, "--------------")

		d.Ack(true)
	}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL