nats

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CorrelationIdKey   = "nbb-correlationId"
	MessageIdKey       = "nbb-messageId"
	PublishTimeKey     = "nbb-publishTime"
	SourceKey          = "nbb-source"
	CommandIdKey       = "CommandId"
	UserIdKey          = "UserId"
	CharismaUserIdKey  = "CharismaUserId"
	MetadataKey        = "Metadata"
	CreationDateKey    = "CreationDate"
	UserIdClaimKey     = "sub"
	CharismaIdClaimKey = "charisma_user_id"
)

Variables

This section is empty.

Functions

func EmptyResponse added in v1.1.1

func EmptyResponse(messageContext messageContext, requestContext context.Context) (bytes []byte, e error)

EmptyResponse returns a empty byte[]

func NBBBuildResponse added in v1.1.1

func NBBBuildResponse(messageContext messageContext, requestContext context.Context) ([]byte, error)

BuildResponse builds the response that is returned by the Gateway after publishing a message

func NBBTransformMessage added in v1.1.1

func NBBTransformMessage(messageContext messageContext, requestContext context.Context, payloadBytes []byte) ([]byte, error)

TransformMessage transforms a message received in the HTTP request to a format required by the NBB infrastructure. It envelopes the message adding the required metadata such as UserId, CorrelationId, MessageId, PublishTime, Source, etc.

func NoTransformation added in v1.1.1

func NoTransformation(messageContext messageContext, requestContext context.Context, payloadBytes []byte) (bytes []byte, e error)

NoTransformation is a no op function

Types

type BuildResponseFunc

type BuildResponseFunc func(messageContext messageContext, requestContext context.Context) ([]byte, error)

BuildResponseFunc builds the response that is returned by the Gateway after publishing a message The returned data will be written to the HTTP response

type CloseConnectionFunc

type CloseConnectionFunc func() error

CloseConnectionFunc is to be called to close the NATS connection

func NewNatsPublisher

func NewNatsPublisher(config Config, options ...Option) (handler.Func, CloseConnectionFunc, error)

NewNatsPublisher creates an instance of the NATS publisher handler. It transforms the received HTTP request using the transformMessageFunc into a message, publishes the message to NATS and returns the http response built using buildResponseFunc

type CommandResult

type CommandResult struct {
	CommandId     uuid.UUID
	CorrelationId uuid.UUID
}

CommandResult is the structure to be returned in the HTTP response

type Config

type Config struct {
	NatsUrl     string `mapstructure:"nats_url"`
	Cluster     string `mapstructure:"cluster"`
	ClientId    string `mapstructure:"client_id"`
	QGroup      string `mapstructure:"q_group"`
	DurableName string `mapstructure:"durable_name"`
	TopicPrefix string `mapstructure:"topic_prefix"`
	Source      string `mapstructure:"source"`
	// contains filtered or unexported fields
}

Config is the global NATS configuration

type EndpointConfig

type EndpointConfig struct {
	Topic string `mapstructure:"topic"`
}

EndpointConfig is the NATS specific configuration of the endpoint

type Message

type Message struct {
	Headers map[string]interface{}
	Payload map[string]interface{}
}

Message is the structure of the message envelope to be published

type Option added in v1.1.1

type Option func(Config) Config

func BuildResponse

func BuildResponse(f BuildResponseFunc) Option

BuildResponse adds a BuildResponseFunc to config

func Logger added in v1.1.1

func Logger(logger log.Logger) Option

Logger adds a logger to config

func TransformMessage

func TransformMessage(f TransformMessageFunc) Option

TransformMessage adds a TransformMessageFunc to config

type TransformMessageFunc

type TransformMessageFunc func(messageContext messageContext, requestContext context.Context, payloadBytes []byte) ([]byte, error)

TransformMessageFunc transforms a message received in the HTTP request to a format required by the NBB infrastructure. It envelopes the message adding the required metadata such as UserId, CorrelationId, MessageId, PublishTime, Source, etc.

Jump to

Keyboard shortcuts

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