broker

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: MIT Imports: 6 Imported by: 1

README

Broker Driver

This is the broker driver package. It is used in almost every service as the way to access RabbitMQ. The Interface in interface.go is implemented by both the actual driver and the mock driver. This allows for the use of a mock broker in usecase testing in services.

Creating a Driver

import "git.science.uu.nl/datastrophe/broker"

broker := broker.NewDriver()

Creating a Mock Driver

import "git.science.uu.nl/datastrophe/broker"

mockBroker := broker.NewMockDriver()

This mockBroker can also be cast explicitly to a MockDriver to allow for access to messages that were sent.

castMockBroker := mockBroker.(*broker.MockDriver)

Producers and Consumers

Producers and consumers can be made using the driver.

Creating Producers
producer := broker.CreateProducer("exchange-name")

To create a producer, only the exchange name has to be passed. To publish a message the PublishMessage(body *[]byte, routingKey string, headers *map[string]interface{}) method can be called.

Creating Consumers
consumer = s.brokerDriver.CreateConsumer("requests-exchange", "arangodb-query-queue", "arangodb-query-request")

consumer.SetMessageHandler(s.HandleMessage)

consumer.ConsumeMessages()

To create a consumer, the exchange name, queue name and routing key need to be given. Then a message handler needs to be given to the consumer. This message handler function should have type func(msg *Message). To start receiving messages the ConsumeMessages() method needs to be called. This starts a goroutine, so keep in mind that this is a non-blocking call.

Documentation

Overview

This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)

This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)

This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver implements the broker interface

func (*Driver) CreateConsumer

func (d *Driver) CreateConsumer(exchangeName string, queueName string, routingKey string, routingKeyStore keyvaluestore.Interface, serviceName string) consumer.BrokerConsumerI

CreateConsumer creates a consumer with the specified parameters

exchangeName: string, the name of the exchange to which this consumer will bind its queue
queueName: string, the name of the queue this consumer will consume messages from
routingKey: string, the routingKey this consumer listens to
Returns: An object implementing the Consumer interface

func (*Driver) CreateConsumerWithClient added in v0.0.3

func (d *Driver) CreateConsumerWithClient(exchangeName string, queueName string, routingKey string, routingKeyStore keyvaluestore.Interface, serviceName string) (consumer.BrokerConsumerI, producer.BrokerProducerI)

func (*Driver) CreateProducer

func (d *Driver) CreateProducer(exchangeName string, serviceName string) producer.BrokerProducerI

CreateProducer creates a producer with the specified parameters

exchangeName: string, the name of the exchange to which this producer will publish messages
Returns: An object implementing the Producer interface

type Interface

type Interface interface {
	CreateConsumer(exchangeName string, queueName string, routingKey string, routingKeyStore keyvaluestore.Interface, serviceName string) consumer.BrokerConsumerI
	CreateConsumerWithClient(exchangeName string, queueName string, routingKey string, routingKeyStore keyvaluestore.Interface, serviceName string) (consumer.BrokerConsumerI, producer.BrokerProducerI)
	CreateProducer(exchangeName string, serviceName string) producer.BrokerProducerI
}

Interface describes the broker driver

func NewDriver

func NewDriver(username, password, address string, port int) Interface

NewDriver creates a new broker driver

Returns: *Driver, the driver for the RabbitMQ broker. Implements the broker Interface

type Message

type Message struct {
	Headers map[string]interface{}
	Body    []byte
}

Message describes the message to be handled by the message consumer

Directories

Path Synopsis
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.

Jump to

Keyboard shortcuts

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