mirror of
https://gitee.com/shikong-sk/go-rabbitmq-study
synced 2025-02-23 15:32:14 +08:00
34 lines
835 B
Go
34 lines
835 B
Go
|
package queue
|
||
|
|
||
|
import (
|
||
|
"github.com/streadway/amqp"
|
||
|
"log"
|
||
|
"skcks.cn/study/rabbitmq/types"
|
||
|
)
|
||
|
|
||
|
func DeclareDirect(channel *amqp.Channel, name string, options ...types.DeclareOptionFunc) error {
|
||
|
defaultOption := &types.DeclareOption{
|
||
|
Name: name,
|
||
|
Durable: true,
|
||
|
AutoDelete: false, //auto-deleted
|
||
|
Internal: false, //internal
|
||
|
NoWait: false, //noWait
|
||
|
Args: nil,
|
||
|
}
|
||
|
|
||
|
option := types.MergeExchangeOptionsWithDefault(defaultOption, options)
|
||
|
// 声明一个queue
|
||
|
if _, err := channel.QueueDeclare(
|
||
|
option.Name, // name
|
||
|
option.Durable, // durable
|
||
|
option.AutoDelete, // delete when unused
|
||
|
option.Exclusive, // exclusive
|
||
|
option.NoWait, // no-wait
|
||
|
option.Args, // arguments
|
||
|
); err != nil {
|
||
|
log.Println("Failed to declare a queue:", err.Error())
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|