fakensq

package
v0.0.0-...-e2ed998 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 4 Imported by: 0

README

Fake NSQ

Fake NSQ Consumer and Producer for backend/internal/pkg/nsq

Built to test the correctness of the nsqio wrapper

Limitations:

  • Consumer must registered first before publishing message.
  • Do not expecting message to be stored, all message directly consumed.
  • Message published before any active consumer will be lost.
  • Message requeue not working
  • Message is always finished

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer is the consumer of NSQ, the consumer relay message to message handler.

func (*Consumer) AddConcurrentHandlers

func (cons *Consumer) AddConcurrentHandlers(handler nsqio.Handler, concurrency int)

AddConcurrentHandlers for nsq

func (*Consumer) AddHandler

func (cons *Consumer) AddHandler(handler nsqio.Handler)

AddHandler for nsq

func (*Consumer) ChangeMaxInFlight

func (cons *Consumer) ChangeMaxInFlight(n int)

ChangeMaxInFlight message in nsq consumer

func (*Consumer) Channel

func (cons *Consumer) Channel() string

Channel return the consumer channel

func (*Consumer) Concurrency

func (cons *Consumer) Concurrency() int

Concurrency return the number of conccurent worker

func (*Consumer) ConnectToNSQLookupds

func (cons *Consumer) ConnectToNSQLookupds(addresses []string) error

ConnectToNSQLookupds for nsq

func (*Consumer) MaxInFlight

func (cons *Consumer) MaxInFlight() int

MaxInFlight return the maximum in flight number for nsq.

func (*Consumer) Stop

func (cons *Consumer) Stop()

Stop consumer backend mock

func (*Consumer) Topic

func (cons *Consumer) Topic() string

Topic return the consumer topic

type ConsumerConfig

type ConsumerConfig struct {
	Topic       string
	Channel     string
	Concurrency int
	MaxInFlight int
}

ConsumerConfig of fake nsq

func (*ConsumerConfig) Validate

func (cc *ConsumerConfig) Validate() error

Validate consumer configuration

type FakeNSQ

type FakeNSQ struct {
	// contains filtered or unexported fields
}

FakeNSQ mimic several NSQ features, mostly for publishing and consuming message. The purpose is to not rely on the real NSQ for testing.

func New

func New() *FakeNSQ

New instance of fakensq

func (*FakeNSQ) NewConsumer

func (fnsq *FakeNSQ) NewConsumer(config ConsumerConfig) *Consumer

NewConsumer return a fakensq consumer for consuming message from fakensq. The consumer will register the topic and channel to fakensq lookupd registrar for topic and channel discovery.

func (*FakeNSQ) NewProducer

func (fnsq *FakeNSQ) NewProducer() *Producer

NewProducer return a fakensq producer for publishing message to fakensq. The producer will automatically publish the message into the designated topic if topic/channel is available.

type LookUpD

type LookUpD struct {
	// contains filtered or unexported fields
}

LookUpD for fakensq. The lookUpD will store all informations of messages channeling for specific topic and channel.

type MessageDelegator

type MessageDelegator struct {
	// contains filtered or unexported fields
}

MessageDelegator implement Delegator of nsqio

func (*MessageDelegator) OnFinish

func (mdm *MessageDelegator) OnFinish(message *nsqio.Message)

func (*MessageDelegator) OnRequeue

func (mdm *MessageDelegator) OnRequeue(m *nsqio.Message, t time.Duration, backoff bool)

func (*MessageDelegator) OnTouch

func (mdm *MessageDelegator) OnTouch(m *nsqio.Message)

type Producer

type Producer struct {
	// contains filtered or unexported fields
}

Producer for fakensq. The producer will publish message to all channels for specific topic, based on information from the lookUpD.

func (*Producer) MultiPublish

func (prod *Producer) MultiPublish(topic string, messages [][]byte) error

MultiPublish message

func (*Producer) Ping

func (prod *Producer) Ping() error

Ping will always return nil

func (*Producer) Publish

func (prod *Producer) Publish(topic string, message []byte) error

Publish a message this function might block if the channel is full

func (*Producer) Stop

func (prod *Producer) Stop()

Stop fake producer

Jump to

Keyboard shortcuts

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