Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,35 @@ export const computeExtendedConsumerId = (consumerId: number, connectionId: stri
}

export interface Consumer {
/**
* Close the publisher
*
* @param {boolean} manuallyClose - Weather you want to close the publisher manually or not
*/
// TODO - clarify the parameter
close(manuallyClose: boolean): Promise<void>

/**
* Store the stream offset on the server
*
* @param {bigint} offsetValue - The value of the offset to save
*/
storeOffset(offsetValue: bigint): Promise<void>

/**
* Get the saved offset on the server
*
* @returns {bigint} The value of the stream offset
*/
queryOffset(): Promise<bigint>

/**
* Gets the infos of the publisher's connection
*
* @returns {ConnectionInfo} Infos on the publisher's connection
*/
getConnectionInfo(): ConnectionInfo

consumerId: number
consumerRef?: string
readonly extendedId: string
Expand Down
63 changes: 63 additions & 0 deletions src/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,78 @@ export const computeExtendedPublisherId = (publisherId: number, connectionId: st
}

export interface Publisher {
/**
* Sends a message in the stream
*
* @param {Buffer} message - The encoded content of the message
* @param {MessageOptions} opts - The optional message options and properties
* @returns {SendResult} Returns a boolean value and the associated publishingId
*/
send(message: Buffer, opts?: MessageOptions): Promise<SendResult>

/**
* Sends a message in the stream with a specific publishingId
*
* @param {bigint} publishingId - The associated publishingId
* @param {Buffer} content - The encoded content of the message
* @param {MessageOptions} opts - The optional message options and properties
* @returns {SendResult} Returns a boolean value and the associated publishingId
*/
basicSend(publishingId: bigint, content: Buffer, opts?: MessageOptions): Promise<SendResult>

/**
* Sends all the accumulated messages on the internal buffer
*
* @returns {boolean} Returns false if there was an error
*/
flush(): Promise<boolean>

/**
* Sends a batch of messages
*
* @param {Message[]} messages - A batch of messages to send
* @param {CompressionType} compressionType - Can optionally compress the messages
*/
sendSubEntries(messages: Message[], compressionType?: CompressionType): Promise<void>

/**
* Setup the listener for the metadata update event
*
* @param {"metadata_update"} event - The name of the event
* @param {MetadataUpdateListener} listener - The listener which will be called when the event is fired
*/
on(event: "metadata_update", listener: MetadataUpdateListener): void

/**
* Setup the listener for the publish confirm event
*
* @param {"publish_confirm"} event - The name of the event
* @param {PublishConfirmCallback} listener - The listener which will be called when the event is fired
*/
on(event: "publish_confirm", listener: PublishConfirmCallback): void

/**
* Gets the last publishing id in the stream
*
* @returns {bigint} Last publishing id
*/
getLastPublishingId(): Promise<bigint>

/**
* Gets the infos of the publisher's connection
*
* @returns {ConnectionInfo} Infos on the publisher's connection
*/
getConnectionInfo(): ConnectionInfo

/**
* Close the publisher
*
* @param {boolean} manuallyClose - Weather you want to close the publisher manually or not
*/
// TODO - clarify the parameter
close(manuallyClose: boolean): Promise<void>

closed: boolean
ref: string
readonly publisherId: number
Expand Down