msghandler

package
v0.0.0-...-57c6170 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package msghandler dynamically maintains the list of registered message services.

In addition to returning list of available message services as a message service provider implementation, this message handler also provides register/unregister functionality which can be used to add/remove message services from already running agent.

(RFC Reference : https://github.com/hyperledger/aries-rfcs/blob/master/features/0351-purpose-decorator/README.md)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registrar

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

Registrar is message service provider implementation which maintains list of registered message service and also allows dynamic register/unregister of message services.

func NewRegistrar

func NewRegistrar() *Registrar

NewRegistrar returns new message registrar instance.

func (*Registrar) Register

func (m *Registrar) Register(msgServices ...dispatcher.MessageService) error

Register registers given message services to this handler, returns error in case of duplicate registration.

Example
registrar := NewRegistrar()

err := registrar.Register(&generic.MockMessageSvc{})
if err != nil {
	fmt.Println(err)
}

fmt.Println("new message service registered")
Output:

new message service registered

func (*Registrar) Services

func (m *Registrar) Services() []dispatcher.MessageService

Services returns list of message services registered to this handler.

Example
registrar := NewRegistrar()

err := registrar.Register(&generic.MockMessageSvc{NameVal: "sample-1"})
if err != nil {
	fmt.Println(err)
}

err = registrar.Register(&generic.MockMessageSvc{NameVal: "sample-2"})
if err != nil {
	fmt.Println(err)
}

services := registrar.Services()
fmt.Println("available services", len(services))
Output:

available services 2

func (*Registrar) Unregister

func (m *Registrar) Unregister(name string) error

Unregister unregisters message service with given name from this message handler, returns error if given message service doesn't exists.

Example
registrar := NewRegistrar()

const serviceName = "sample-service"

err := registrar.Register(&generic.MockMessageSvc{NameVal: serviceName})
if err != nil {
	fmt.Println(err)
}

err = registrar.Unregister(serviceName)
if err != nil {
	fmt.Println(err)
}

fmt.Println("message service unregistered")
Output:

message service unregistered

Jump to

Keyboard shortcuts

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