Documentation ¶
Index ¶
- type MongoDbConnection
- func (c *MongoDbConnection) Close(correlationId string) error
- func (c *MongoDbConnection) Configure(config *cconf.ConfigParams)
- func (c *MongoDbConnection) GetConnection() *mongodrv.Client
- func (c *MongoDbConnection) GetDatabase() *mongodrv.Database
- func (c *MongoDbConnection) GetDatabaseName() string
- func (c *MongoDbConnection) IsOpen() bool
- func (c *MongoDbConnection) Open(correlationId string) error
- func (c *MongoDbConnection) SetReferences(references crefer.IReferences)
- type MongoDbConnectionResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoDbConnection ¶ added in v1.1.0
type MongoDbConnection struct { Ctx context.Context // 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 ¶ added in v1.1.0
func NewMongoDbConnection() *MongoDbConnection
NewMongoDbConnection are creates a new instance of the connection component. Returns *MongoDbConnection with default config
func (*MongoDbConnection) Close ¶ added in v1.1.0
func (c *MongoDbConnection) Close(correlationId string) error
Close method is closes component and frees used resources. Parameters:
- correlationId string (optional) transaction id to trace execution through call chain.
Return error error or nil when no errors occured.
func (*MongoDbConnection) Configure ¶ added in v1.1.0
func (c *MongoDbConnection) Configure(config *cconf.ConfigParams)
Configure is configures component by passing configuration parameters. Parameters:
- config *cconf.ConfigParams configuration parameters to be set.
func (*MongoDbConnection) GetConnection ¶ added in v1.1.0
func (c *MongoDbConnection) GetConnection() *mongodrv.Client
GetConnection method return work connection object Return *mongodrv.Client
func (*MongoDbConnection) GetDatabase ¶ added in v1.1.0
func (c *MongoDbConnection) GetDatabase() *mongodrv.Database
GetDatabase method retrun work database object Return *mongodrv.Database
func (*MongoDbConnection) GetDatabaseName ¶ added in v1.1.0
func (c *MongoDbConnection) GetDatabaseName() string
GetDatabaseName method retruns name of work database Return string
func (*MongoDbConnection) IsOpen ¶ added in v1.1.0
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 ¶ added in v1.1.0
func (c *MongoDbConnection) Open(correlationId string) error
Open method is opens the component. Parameters:
- correlationId string (optional) transaction id to trace execution through call chain.
Return error error or nil when no errors occured.
func (*MongoDbConnection) SetReferences ¶ added in v1.1.0
func (c *MongoDbConnection) SetReferences(references crefer.IReferences)
SetReferences are sets references to dependent components. Parameters:
- 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 Retruns *MongoDbConnectionResolver
func (*MongoDbConnectionResolver) Configure ¶
func (c *MongoDbConnectionResolver) Configure(config *cconf.ConfigParams)
Configure is configures component by passing configuration parameters. Parameters:
- config *cconf.ConfigParams configuration parameters to be set.
func (*MongoDbConnectionResolver) Resolve ¶
func (c *MongoDbConnectionResolver) Resolve(correlationId string) (uri string, err error)
Resolve method are resolves MongoDB connection URI from connection and credential parameters. Parameters:
- 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(references crefer.IReferences)
SetReferences is sets references to dependent components. Parameters:
- references crefer.IReferences references to locate the component dependencies.