Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
timeToLive optional fix #311
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed May 2, 2023
1 parent 28f3d67 commit f16efaa
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
_New shiny stuff._
- Add `ZBClient.broadcastSignal`, enabling the client to broadcast a signal. See [#312](https://github.com/camunda-community-hub/zeebe-client-node-js/issues/312) for more details.

## Fixes

_Things that were broken and are now fixed._

- Previously, the `timeToLive` property of `ZBClient.publishMessage` was required, although it was documented as optional. In this release, both `timeToLive` and `variables` have been made optional. If no value is supplied for `timeToLive`, it defaults to 0. Thanks to [@nhomble]() for raising this issue. See [#311](https://github.com/camunda-community-hub/zeebe-client-node-js/issues/311) for more details.

# Version 8.2.0

## New Features
Expand Down
54 changes: 54 additions & 0 deletions src/__tests__/integration/Client-PublishMessage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { v4 as uuid } from 'uuid'
import { ZBClient } from '../..'
import { createUniqueTaskType } from '../../lib/createUniqueTaskType'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(45000)
let zbc: ZBClient

beforeEach(async () => {
zbc = new ZBClient()
})

afterEach(async () => {
await zbc.close()
})

test('Can publish a message', () =>
new Promise(async done => {
const { bpmn, taskTypes, processId, messages } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/Client-MessageStart.bpmn',
messages: ['MSG-START_JOB'],
taskTypes: ['console-log-msg-start'],
})

const deploy = await zbc.deployProcess({
definition: bpmn,
name: `Client-MessageStart-${processId}.bpmn`,
})
expect(deploy.key).toBeTruthy()

const randomId = uuid()

// Wait 1 second to make sure the deployment is complete
await new Promise(res => setTimeout(() => res(null), 1000))

await zbc.publishMessage({
name: messages['MSG-START_JOB'],
variables: {
testKey: randomId,
},
correlationKey: 'something'
})

zbc.createWorker({
taskType: taskTypes['console-log-msg-start'],
taskHandler: async job => {
const res = await job.complete()
expect(job.variables.testKey).toBe(randomId) // Makes sure the worker isn't responding to another message
done(null)
return res
},
loglevel: 'NONE',
})
}))
4 changes: 2 additions & 2 deletions src/lib/interfaces-grpc-1.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ export interface PublishMessageRequest<Variables = IInputVariables> {
/** The value to match with the field specified as "Subscription Correlation Key" in BPMN */
correlationKey: string
/** The number of seconds for the message to buffer on the broker, awaiting correlation. Omit or set to zero for no buffering. */
timeToLive: MaybeTimeDuration
timeToLive?: MaybeTimeDuration
/** Unique ID for this message */
messageId?: string
variables: Variables
variables?: Variables
}

export interface PublishMessageResponse {
Expand Down
10 changes: 8 additions & 2 deletions src/zb/ZBClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,10 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
): Promise<Grpc.PublishMessageResponse> {
return this.executeOperation('publishMessage', () =>
this.grpc.publishMessageSync(
stringifyVariables(publishMessageRequest)
stringifyVariables({
...publishMessageRequest,
variables: publishMessageRequest.variables
})
)
)
}
Expand Down Expand Up @@ -1086,7 +1089,10 @@ export class ZBClient extends TypedEmitter<typeof ConnectionStatusEvent> {
}
return this.executeOperation('publishStartMessage', () =>
this.grpc.publishMessageSync(
stringifyVariables(publishMessageRequest)
stringifyVariables({
...publishMessageRequest,
variables: publishMessageRequest.variables || {}
})
)
)
}
Expand Down

0 comments on commit f16efaa

Please sign in to comment.