connect

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoDbConnection

type MongoDbConnection struct {

	// The logger.
	Logger *clog.CompositeLogger
	//   The connection resolver.
	ConnectionResolver *MongoDbConnectionResolver
	//   The configuration options.
	Options *cconf.ConfigParams
	//   The MongoDB connection object.
	Connection *mongodrv.Client
	//   The MongoDB database name.
	DatabaseName string
	//   The MongoDb database object.
	Db *mongodrv.Database
	// contains filtered or unexported fields
}

MongoDbConnection struct help creates new connections to MongoDB MongoDB connection using plain driver.

By defining a connection and sharing it through multiple persistence components you can reduce number of used database connections.

Configuration parameters:
	- connection(s):
		- discovery_key:             (optional) a key to retrieve the connection from IDiscovery
		- host:                      host name or IP address
		- port:                      port number (default: 27017)
		- uri:                       resource URI or connection string with all parameters in it
	- credential(s):
		- store_key:                 (optional) a key to retrieve the credentials from ICredentialStore
		- username:                  (optional) user name
		- password:                  (optional) user password
	- options:
		- max_pool_size:             (optional) maximum connection pool size (default: 2)
		- keep_alive:                (optional) enable connection keep alive in ms, if zero connection are keeped indefinitely (default: 0)
		- connect_timeout:           (optional) connection timeout in milliseconds (default: 5000)
		- socket_timeout:            (optional) socket timeout in milliseconds (default: 360000)
		- auto_reconnect:            (optional) enable auto reconnection (default: true) (Not used)
		- reconnect_interval:        (optional) reconnection interval in milliseconds (default: 1000) (Not used)
		- max_page_size:             (optional) maximum page size (default: 100)
		- replica_set:               (optional) name of replica set
		- ssl:                       (optional) enable SSL connection (default: false) (Not release in this version)
		- auth_source:               (optional) authentication source
		- debug:                     (optional) enable debug output (default: false). (Not used)

References:
	- *:logger:*:*:1.0           (optional) ILogger components to pass log messages
	- *:discovery:*:*:1.0        (optional) IDiscovery services
	- *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials

func NewMongoDbConnection

func NewMongoDbConnection() *MongoDbConnection

NewMongoDbConnection are creates a new instance of the connection component. Returns *MongoDbConnection with default config

func (*MongoDbConnection) Close

func (c *MongoDbConnection) Close(ctx context.Context, correlationId string) error

Close method is closes component and frees used resources.

Parameters:
	- ctx context.Context
	- correlationId string(optional) transaction id to trace execution through call chain.
Returns: error or nil when no errors occurred.

func (*MongoDbConnection) Configure

func (c *MongoDbConnection) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure is configures component by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config  *cconf.ConfigParams configuration parameters to be set.

func (*MongoDbConnection) GetConnection

func (c *MongoDbConnection) GetConnection() *mongodrv.Client

GetConnection method return work connection object

Returns: *mongodrv.Client

func (*MongoDbConnection) GetDatabase

func (c *MongoDbConnection) GetDatabase() *mongodrv.Database

GetDatabase method retrun work database object

Returns: *mongodrv.Database

func (*MongoDbConnection) GetDatabaseName

func (c *MongoDbConnection) GetDatabaseName() string

GetDatabaseName method reruns name of work database

Returns: string

func (*MongoDbConnection) IsOpen

func (c *MongoDbConnection) IsOpen() bool

IsOpen method is checks if the component is opened.

Returns: true if the component has been opened and false otherwise.

func (*MongoDbConnection) Open

func (c *MongoDbConnection) Open(ctx context.Context, correlationId string) error

Open method is opens the component.

Parameters:
	- ctx context.Context
	- correlationId string (optional) transaction id to trace execution through call chain.
Returns: error or nil when no errors occurred.

func (*MongoDbConnection) SetReferences

func (c *MongoDbConnection) SetReferences(ctx context.Context, references crefer.IReferences)

SetReferences are sets references to dependent components.

Parameters:
	- ctx context.Context
	- references crefer.IReferences references to locate the component dependencies.

type MongoDbConnectionResolver

type MongoDbConnectionResolver struct {
	//The connections resolver.
	ConnectionResolver ccon.ConnectionResolver
	//The credentials resolver.
	CredentialResolver auth.CredentialResolver
}

MongoDbConnectionResolver a helper struct that resolves MongoDB connection and credential parameters, validates them and generates a connection URI. It is able to process multiple connections to MongoDB cluster nodes.

Configuration parameters
	- connection(s):
		- discovery_key:               (optional) a key to retrieve the connection from IDiscovery
		- host:                        host name or IP address
		- port:                        port number (default: 27017)
		- database:                    database name
		- uri:                         resource URI or connection string with all parameters in it
	- credential(s):
		- store_key:                   (optional) a key to retrieve the credentials from ICredentialStore
		- username:                    user name
		- password:                    user password
References
	- *:discovery:*:*:1.0             (optional) IDiscovery services
	- *:credential-store:*:*:1.0      (optional) Credential stores to resolve credentials

func NewMongoDbConnectionResolver

func NewMongoDbConnectionResolver() *MongoDbConnectionResolver

NewMongoDbConnectionResolver creates new connection resolver

Returns: *MongoDbConnectionResolver

func (*MongoDbConnectionResolver) Configure

func (c *MongoDbConnectionResolver) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure is configures component by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config  *cconf.ConfigParams configuration parameters to be set.

func (*MongoDbConnectionResolver) Resolve

func (c *MongoDbConnectionResolver) Resolve(ctx context.Context, correlationId string) (uri string, err error)

Resolve method are resolves MongoDB connection URI from connection and credential parameters.

Parameters:
	- ctx context.Context
	- correlationId  string (optional) transaction id to trace execution through call chain.
Returns: uri string, err error resolved URI and error, if this occured.

func (*MongoDbConnectionResolver) SetReferences

func (c *MongoDbConnectionResolver) SetReferences(ctx context.Context, references crefer.IReferences)

SetReferences is sets references to dependent components.

Parameters:
	- ctx context.Context,
	- references crefer.IReferences references to locate the component dependencies.

Jump to

Keyboard shortcuts

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