rmq_consumer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Env = []templates.Environment{
	{Name: "ConsumerAddress", Type: "string", Env: "CONSUMER_ADDR", Default: "amqp://guest:guest@localhost:5672"},
	{Name: "ConsumerExchange", Type: "string", Env: "CONSUMER_EXCHANGE"},
	{Name: "ConsumerQueue", Type: "string", Env: "CONSUMER_QUEUE"},
	{Name: "ConsumerRoutingKey", Type: "string", Env: "CONSUMER_ROUTING_KEY"},
}
View Source
var Libs = []templates.Library{
	{Name: "errors"},
	{Name: "github.com/streadway/amqp"},
}
View Source
var Models = map[string]string{
	"RabbitMq": `
type RabbitMq struct {
	Connection *amqp.Connection
	Channel    *amqp.Channel
	Queue      *amqp.Queue
}`,
}
View Source
var Props = []templates.Property{
	{Name: "Consumer", Type: "*RabbitMq", Default: "new(RabbitMq)"},
}
View Source
var TemplateRunFunction = `` /* 208-byte string literal not displayed */
View Source
var TemplateSetter = `` /* 260-byte string literal not displayed */
View Source
var TemplateSetterFunction = `` /* 860-byte string literal not displayed */
View Source
var Templates = map[string]string{
	"app/consumer.go": `package app

import (
	"go.uber.org/zap"
	"github.com/streadway/amqp"
)

func (a *Application) RunConsumer(consumer *RabbitMq, queue string) (err error) {
	a.Logger.Info("consumer start")
	msgs, err := consumer.Channel.Consume(
		queue,
		"{{.Name}}-consumer",
		false,
		false,
		false,
		false,
		nil,
	)
	if err != nil {
		return err
	}

	go func() {
		defer func() {
			consumer.Connection.Close()
		}()
		for {
			select {
			case msg := <-msgs:
				a.Logger.Debug("income message", zap.ByteString("message", msg.Body))
				if len(msg.Body) > 0 {
					go a.consumerHandle(&msg)
				}
			}
		}
	}()

	return nil
}

func (a *Application) consumerHandle(msg *amqp.Delivery) {
	//TODO: Implement me
	msg.Ack(false)
}
`,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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