import {TCPConnection} from 'eventstore-ts-client/src/eventstore/TCPConnection.ts'
TCPConnection
Extends:
Raw tcp communication to eventstore This class handles basic communication with eventstore
Constructor Summary
Public Constructor | ||
public |
Creates an instance of TCPConnection. |
Member Summary
Public Members | ||
public get |
Returns true if connected to eventstore otherwise false |
|
public |
logger instance |
Protected Members | ||
protected |
config after discovery process |
|
protected |
connection id |
|
protected |
initial config |
|
protected |
indicates if connection close is wanted by user or not |
|
protected |
message length of tcp data |
|
protected |
message offset of tcp data |
|
protected |
messageData: Buffer | null message buffer of tcp data |
|
protected |
list of pending requests |
|
protected |
list of persistent subscriptions |
|
protected |
counter for re-connections |
|
protected |
socket: SOMEUNKNOWN | SOMEUNKNOWN tcp socket |
|
protected |
state: connectionState connection state |
|
protected |
list of subscriptions |
|
protected |
timeoutInterval: null | SOMEUNKNOWN timeout interval for timed out pending requests |
Method Summary
Public Methods | ||
public |
Called to connect to eventstore |
|
public |
async connectToPersistentSubscription(subscription: PersistentSubscription, allowedInFlightMessages: number, credentials: UserCredentials | null): Promise Connects to persistent subscription |
|
public |
async disconnect(): Promise Disconnect from eventstore. |
|
public |
sendCommand(correlationId: , command: EventstoreCommand, data: Buffer | null, credentials: UserCredentials | null, promise: null): void Creates and sends raw data message to eventstore and adds given promise to pending queue |
|
public |
subscribeToStream(stream: Stream, resolveLinkTos: boolean, credentials: UserCredentials | null): Promise Subscribes to stream |
|
public |
async unsubscribeFromPersistentSubscription(subscriptionId: , credentials: UserCredentials | null): Promise Stop listening on persistent subscription |
|
public |
async unsubscribeFromStream(subscriptionId: ): Promise Unsubscribes from stream |
Protected Methods | ||
protected |
checkOperationResult(correlationId: , result: , message: string): boolean CHecks if given result is an error code It returns true for successful result otherwise it returns false. |
|
protected |
checkTimeout(): void Called by interval function to check if there are some pending requests which should be rejected with time out error |
|
protected |
handleCreatePersistentSubscriptionCompleted(correlationId: , payload: Buffer): void Handle response for command CreatePersistentSubscription |
|
protected |
handleDeletePersistentSubscriptionCompleted(correlationId: , payload: Buffer): void Handle response for command DeletePersistentSubscription |
|
protected |
handleDeleteStreamCompleted(correlationId: , payload: Buffer): void Handle response for command DeleteStreamCompleted |
|
protected |
handleMultiPacketResponseData(data: Buffer): Buffer | null This function handles raw buffer responses received within multiple tcp data package |
|
protected |
handleNewResponseData(data: Buffer): Buffer | null Gets called as soon as new data over tcp connection arrives as raw buffer data Checks if
|
|
protected |
handlePersistentSubscriptionConfirmation(correlationId: , payload: Buffer): void Handles persistent subscription confirmation |
|
protected |
handlePersistentSubscriptionStreamEventAppeared(correlationId: , payload: Buffer): void Handles persistent subscription stream event appeared |
|
protected |
handleReadAllEventsCompleted(correlationId: , payload: Buffer): void Handle response for command ReadAllEvents |
|
protected |
handleReadEventCompleted(correlationId: , payload: Buffer): void Handle response for command ReadEvent |
|
protected |
handleReadStreamEventsCompleted(correlationId: , payload: Buffer): void Handle response for command ReadStreamEvents |
|
protected |
handleSingleResponseData(data: Buffer): void This function handles a single raw buffer response |
|
protected |
handleStreamEventAppeared(correlationId: , payload: Buffer): void Handle incoming event for subscription |
|
protected |
handleSubscriptionConfirmation(correlationId: , payload: Buffer): void Handle response for command Subscription |
|
protected |
handleSubscriptionDropped(correlationId: , payload: Buffer): void Handle subscription drop |
|
protected |
handleTransactionCommitCompleted(correlationId: , payload: Buffer): void Handle response for command TransactionCommit |
|
protected |
handleTransactionStartCompleted(correlationId: , payload: Buffer): void Handle response for command TransactionStart |
|
protected |
handleTransactionWriteCompleted(correlationId: , payload: Buffer): void Handles transaction write completed |
|
protected |
handleUpdatePersistentSubscriptionCompleted(correlationId: , payload: Buffer): void Handles update persistent subscription completed |
|
protected |
handleWriteEventsCompleted(correlationId: , payload: Buffer): void Handles write events completed |
|
protected |
onClose(): void Emit as soon as connection to eventstore is closed |
|
protected |
onConnect(): void Emit as soon as connection to eventstore was established successfully |
|
protected |
Emitted as soon as data arrives over tcp connection |
|
protected |
onDrain(): void Emit when connection starts draining |
|
protected |
Emit general low level connection errors (communication errors). |
|
protected |
onSecureConnect(): void Emit when connection secured |
|
protected |
rejectCommandPromise(correlationId: , error: ): void Will be called if a command send to eventstore was replied with an error In this case corresponding promise will be rejected and removed from queue |
|
protected |
resolveCommandPromise(correlationId: , result: null | T): void Will be called if a command send to eventstore was replied with success response In this case corresponding promise will be resolved with result received from eventstore |
|
protected |
async tryToConnect(): Promise Connect to eventstore |
Public Constructors
Public Members
Protected Members
Public Methods
public async connectToPersistentSubscription(subscription: PersistentSubscription, allowedInFlightMessages: number, credentials: UserCredentials | null): Promise source
Connects to persistent subscription
Params:
Name | Type | Attribute | Description |
subscription | PersistentSubscription | ||
allowedInFlightMessages | number |
|
|
credentials | UserCredentials | null |
public async disconnect(): Promise source
Disconnect from eventstore. It tries to drain pending queue to prevent data loose before connection gets closed If disconnect() is call no new outgoing requests accepted
public sendCommand(correlationId: , command: EventstoreCommand, data: Buffer | null, credentials: UserCredentials | null, promise: null): void source
Creates and sends raw data message to eventstore and adds given promise to pending queue
Params:
Name | Type | Attribute | Description |
correlationId | |||
command | EventstoreCommand | ||
data | Buffer | null |
|
|
credentials | UserCredentials | null |
|
|
promise | null |
|
public subscribeToStream(stream: Stream, resolveLinkTos: boolean, credentials: UserCredentials | null): Promise source
Subscribes to stream
Params:
Name | Type | Attribute | Description |
stream | Stream | ||
resolveLinkTos | boolean |
|
|
credentials | UserCredentials | null |
public async unsubscribeFromPersistentSubscription(subscriptionId: , credentials: UserCredentials | null): Promise source
Stop listening on persistent subscription
Params:
Name | Type | Attribute | Description |
subscriptionId | |||
credentials | UserCredentials | null |
public async unsubscribeFromStream(subscriptionId: ): Promise source
Unsubscribes from stream
Params:
Name | Type | Attribute | Description |
subscriptionId |
Protected Methods
protected checkOperationResult(correlationId: , result: , message: string): boolean source
CHecks if given result is an error code It returns true for successful result otherwise it returns false. If result is an error this function rejects corresponding command promise and remove it from command queue
Params:
Name | Type | Attribute | Description |
correlationId | |||
result | |||
message | string |
|
protected checkTimeout(): void source
Called by interval function to check if there are some pending requests which should be rejected with time out error
protected handleCreatePersistentSubscriptionCompleted(correlationId: , payload: Buffer): void source
Handle response for command CreatePersistentSubscription
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleDeletePersistentSubscriptionCompleted(correlationId: , payload: Buffer): void source
Handle response for command DeletePersistentSubscription
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleDeleteStreamCompleted(correlationId: , payload: Buffer): void source
Handle response for command DeleteStreamCompleted
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleMultiPacketResponseData(data: Buffer): Buffer | null source
This function handles raw buffer responses received within multiple tcp data package
Params:
Name | Type | Attribute | Description |
data | Buffer |
protected handleNewResponseData(data: Buffer): Buffer | null source
Gets called as soon as new data over tcp connection arrives as raw buffer data Checks if
- new received data is part of previously received data
- new data contains multiple responses
- new data is single response
Params:
Name | Type | Attribute | Description |
data | Buffer |
protected handlePersistentSubscriptionConfirmation(correlationId: , payload: Buffer): void source
Handles persistent subscription confirmation
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handlePersistentSubscriptionStreamEventAppeared(correlationId: , payload: Buffer): void source
Handles persistent subscription stream event appeared
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleReadAllEventsCompleted(correlationId: , payload: Buffer): void source
Handle response for command ReadAllEvents
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleReadEventCompleted(correlationId: , payload: Buffer): void source
Handle response for command ReadEvent
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleReadStreamEventsCompleted(correlationId: , payload: Buffer): void source
Handle response for command ReadStreamEvents
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleSingleResponseData(data: Buffer): void source
This function handles a single raw buffer response
Params:
Name | Type | Attribute | Description |
data | Buffer |
protected handleStreamEventAppeared(correlationId: , payload: Buffer): void source
Handle incoming event for subscription
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleSubscriptionConfirmation(correlationId: , payload: Buffer): void source
Handle response for command Subscription
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleSubscriptionDropped(correlationId: , payload: Buffer): void source
Handle subscription drop
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleTransactionCommitCompleted(correlationId: , payload: Buffer): void source
Handle response for command TransactionCommit
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleTransactionStartCompleted(correlationId: , payload: Buffer): void source
Handle response for command TransactionStart
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleTransactionWriteCompleted(correlationId: , payload: Buffer): void source
Handles transaction write completed
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleUpdatePersistentSubscriptionCompleted(correlationId: , payload: Buffer): void source
Handles update persistent subscription completed
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected handleWriteEventsCompleted(correlationId: , payload: Buffer): void source
Handles write events completed
Params:
Name | Type | Attribute | Description |
correlationId | |||
payload | Buffer |
protected onConnect(): void source
Emit as soon as connection to eventstore was established successfully
protected onData(data: Buffer | null): void source
Emitted as soon as data arrives over tcp connection
Params:
Name | Type | Attribute | Description |
data | Buffer | null |
protected onError(err: Error): void source
Emit general low level connection errors (communication errors). Will not emit errors on business level
Params:
Name | Type | Attribute | Description |
err | Error |
protected rejectCommandPromise(correlationId: , error: ): void source
Will be called if a command send to eventstore was replied with an error In this case corresponding promise will be rejected and removed from queue
Params:
Name | Type | Attribute | Description |
correlationId | |||
error |
protected resolveCommandPromise(correlationId: , result: null | T): void source
Will be called if a command send to eventstore was replied with success response In this case corresponding promise will be resolved with result received from eventstore
Params:
Name | Type | Attribute | Description |
correlationId | |||
result | null | T |
|