Giter Club home page Giter Club logo

gormq's Introduction

gormq

golang rabbitmq

使用方式

# 创建rabbitmq连接
addr := "amqp://admin:[email protected]:5672"
rabbitmq := gormq.New(addr)

# 队列和交换机 创建
queueExchange := gormq.QueueExchange{
    QueueName:    "myname11",
    RoutingKey:   "iot.report.opendoor.insert",
    ExchangeName: "iot.opendoor",
    ExchangeType: "topic",
}

# 额外参数的默认值为
var DefaultExtras = Extras{
	QueueDurable:       true,
	QueueAutoDelete:    false,
	QueueExclusive:     false,
	QueueNoWait:        true,
	QueueArgs:          nil,
	ExchangeDurable:    true,
	ExchangeAutoDelete: false,
	ExchangeExclusive:  false,
	ExchangeNoWait:     true,
	ExchangeArgs:       nil,
	BindArgs:           nil,
}

# 设置 额外的参数 配置(每一项都是可选的)
extras := []gormq.ExtraFunc{
    gormq.SetQueueDurable(true),
    gormq.SetQueueAutoDelete(false),
    gormq.SetQueueExclusive(false),
    gormq.SetQueueNoWait(true),
    gormq.SetQueueArgs(map[string]interface{}{
        "x-message-ttl": 30000,
    }),

    gormq.SetExchangeDurable(true),
    gormq.SetExchangeAutoDelete(false),
    gormq.SetExchangeExclusive(false),
    gormq.SetExchangeNoWait(true),
    gormq.SetExchangeArgs(map[string]interface{}{
        
    }),
}

# 创建消费者
consumer := rabbitmq.NewConsumer(queueExchange, extras...)

# 消费数据
consumer.Receive(func(msg amqp.Delivery) {
    msg.Ack(false)
    fmt.Println(string(msg.Body))
})

# 创建生产者
publisher := rabbitmq.NewPublisher(queueExchange, extras...)

# 发送消息
err := publisher.Pub([]byte("hhshs"))
fmt.Println(err)

# 发送原始数据
publisher.PubRaw(amqp.Publishing{
    ContentType: "text/plain",
    Body:        []byte("dhhs"),
})

todo

  • err 返回打印

gormq's People

Contributors

haobird avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.