rabbitmq

package
v2.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

package rabbitmq

import ( "testing" "time" )

func TestConsume(t *testing.T) { client,err := NewRecvClient(RecvConfig{ Config:Config{ User:"admin", Password:"admin", Host:"10.1.11.127", Port:5672, VHost:"Affair", }, ExName:"Affair.Exchange", QueueName:"Test", RouteKey:"Test.#", });

if err != nil {
	t.Log(err);
	t.Errorf("TestConsume failed");
}

f := func(msg []byte) bool {
	str := string(msg);
	t.Log(str);
	return true;
};

err = client.Consume(f,true);
if err != nil {
	t.Log(err);
	t.Errorf("TestConsume failed");
}

time.Sleep(20*time.Second);

}

package rabbitmq

import ( "testing" )

func TestSend(t *testing.T) { client,err := NewSendClient(SendConfig{ Config:Config{ User:"admin", Password:"admin", Host:"10.1.11.127", Port:5672, VHost:"Affair", }, ExName:"Affair.Exchange", });

if err != nil {
	t.Log(err);
	t.Errorf("TestSend failed");
}

msg := "this is a new message from test send";
err = client.Send("Test.1",[]byte(msg));

if err != nil {
	t.Log(err);
	t.Errorf("TestSend failed");
}

t.Logf("send result is %s",err);

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	User     string
	Password string
	Host     string
	Port     int
	VHost    string
}

type RabbitMQClient

type RabbitMQClient struct {
	Ch        *amqp.Channel
	ExName    string
	QueueName string
}

func NewRecvClient

func NewRecvClient(c RecvConfig) (*RabbitMQClient, error)

func NewSendClient

func NewSendClient(c SendConfig) (*RabbitMQClient, error)

func (*RabbitMQClient) Consume

func (c *RabbitMQClient) Consume(f RecvHander, isPallal bool) error

func (*RabbitMQClient) Send

func (c *RabbitMQClient) Send(routeKey string, msg []byte) error

type RecvConfig

type RecvConfig struct {
	Config
	ExName    string
	QueueName string
	RouteKey  string
}

type RecvHander

type RecvHander func(msg []byte) bool

type SendConfig

type SendConfig struct {
	Config
	ExName string
}

Jump to

Keyboard shortcuts

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