Documentation
¶
Index ¶
- func NewEventBus(url string) (messaging.EventBus, error)
- func NewEventBusFromConfig(config *messaging.Config) (messaging.EventBus, error)
- func NewPublisher(url string) (messaging.Publisher, error)
- func NewSubscriber(url string) (messaging.Subscriber, error)
- func NewSubscriberWithOptions(url string, opts messaging.SubscriberOptions) (messaging.Subscriber, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEventBus ¶
NewEventBus 创建 RabbitMQ 事件总线
url 格式:amqp://username:password@host:port/vhost 例如:amqp://guest:guest@localhost:5672/
使用示例:
bus, err := rabbitmq.NewEventBus("amqp://guest:guest@localhost:5672/")
if err != nil {
log.Fatal(err)
}
defer bus.Close()
// 使用发布者
publisher := bus.Publisher()
publisher.Publish(ctx, "user.created", data)
// 使用订阅者
subscriber := bus.Subscriber()
subscriber.Subscribe("user.created", "email-service", handler)
func NewEventBusFromConfig ¶
NewEventBusFromConfig 从配置创建事件总线
func NewPublisher ¶
NewPublisher 创建 RabbitMQ 发布者
url 格式:amqp://username:password@host:port/vhost 例如:amqp://guest:guest@localhost:5672/
func NewSubscriber ¶
func NewSubscriber(url string) (messaging.Subscriber, error)
func NewSubscriberWithOptions ¶ added in v0.6.6
func NewSubscriberWithOptions(url string, opts messaging.SubscriberOptions) (messaging.Subscriber, error)
NewSubscriberWithOptions enables bounded retry topology when MaxAttempts is positive. Zero options preserve the historical immediate-requeue behavior.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.