How to use the @node-ts/bus-messages.MessageAttributes function in @node-ts/bus-messages

To help you get started, we’ve selected a few @node-ts/bus-messages examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-ts / bus / packages / bus-workflow / src / workflow / registry / handles-proxy.spec.ts View on Github external
describe('when getting workflow data for an undefined message property', () => {
    let comand: TestCommand
    const messageOptions = new MessageAttributes()

    beforeEach(() => {
      comand = new TestCommand(undefined)
    })

    it('should return an empty set of workflow data', async () => {
      const result = await sut.getWorkflowData(comand, messageOptions)
      expect(result).toHaveLength(0)
    })
  })
})
github node-ts / bus / packages / bus-rabbitmq / src / rabbitmq-transport.ts View on Github external
private async publishMessage (
    message: Message,
    messageOptions: MessageAttributes = new MessageAttributes()
  ): Promise {
    await this.assertExchange(message.$name)
    const payload = JSON.stringify(message)
    this.channel.publish(message.$name, '', Buffer.from(payload), {
      correlationId: messageOptions.correlationId,
      headers: {
        attributes: messageOptions.attributes ? JSON.stringify(messageOptions.attributes) : undefined,
        stickyAttributes: messageOptions.stickyAttributes ? JSON.stringify(messageOptions.stickyAttributes) : undefined
      }
    })
  }
}
github node-ts / bus / packages / bus-workflow / src / workflow / decorators / started.spec.ts View on Github external
beforeAll(async () => {
            await bus.publish(
              finalTask,
              new MessageAttributes({ correlationId: nextWorkflowData[0].$workflowId })
            )
            await sleep(CONSUME_TIMEOUT)

            finalWorkflowData = await persistence.getWorkflowData(
              AssignmentWorkflowData,
              propertyMapping,
              finalTask,
              messageOptions,
              true
            )
          })
github node-ts / bus / packages / bus-core / src / transport / memory-queue.spec.ts View on Github external
describe('MemoryQueue', () => {
  let sut: MemoryQueue
  const handledMessageNames = [TestCommand.NAME, TestEvent.NAME]
  const messageOptions = new MessageAttributes({
    correlationId: faker.random.uuid()
   })

  beforeEach(async () => {
    sut = new MemoryQueue(
      Mock.ofType().object
    )

    const handlerRegistry = Mock.ofType()
    handlerRegistry
      .setup(h => h.getMessageNames())
      .returns(() => handledMessageNames)

    await sut.initialize(handlerRegistry.object)
  })
github node-ts / bus / packages / bus-rabbitmq / src / rabbitmq-transport.integration.ts View on Github external
describe('from a queue with messages', () => {
        const command = new TestCommand()
        let message: TransportMessage | undefined
        const messageOptions = new MessageAttributes({
          correlationId: faker.random.uuid(),
          attributes: {
            attribute1: 'a',
            attribute2: 1
          },
          stickyAttributes: {
            attribute1: 'b',
            attribute2: 2
          }
        })

        beforeEach(async () => {
          await bus.send(command, messageOptions)
          message = await sut.readNextMessage()
        })
github node-ts / bus / packages / bus-workflow / src / workflow / persistence / in-memory-persistence.spec.ts View on Github external
describe('when getting workflow data', () => {
    const messageOptions = new MessageAttributes()

    beforeEach(async () => {
      const mapping = new MessageWorkflowMapping(
        command => command.property1,
        'property1'
      )
      await sut.initializeWorkflow(
        TestWorkflowData,
        [mapping]
      )
    })

    describe('when the mapper doesn\'t resolve', () => {
      let result: TestWorkflowData[]

      beforeEach(async () => {
github node-ts / bus / packages / bus-workflow / src / workflow / workflow.integration.ts View on Github external
beforeAll(async () => {
          await bus.publish(
            finalTask,
            new MessageAttributes({ correlationId: nextWorkflowData[0].$workflowId })
          )
          await sleep(CONSUME_TIMEOUT)

          finalWorkflowData = await persistence.getWorkflowData(
            TestWorkflowData,
            propertyMapping,
            command,
            messageOptions,
            true
          )
        })
github node-ts / bus / packages / bus-core / src / service-bus / service-bus.ts View on Github external
async publish (
    event: TEvent,
    messageOptions: MessageAttributes = new MessageAttributes()
  ): Promise {
    this.logger.debug('publish', { event })
    const transportOptions = this.prepareTransportOptions(messageOptions)
    return this.transport.publish(event, transportOptions)
  }
github node-ts / bus / packages / bus-sqs / src / sqs-transport.ts View on Github external
export function fromMessageAttributeMap (sqsAttributes: SqsMessageAttributes | undefined): MessageAttributes {
  const messageOptions = new MessageAttributes()

  if (sqsAttributes) {
    messageOptions.correlationId = sqsAttributes.correlationId
      ? sqsAttributes.correlationId.Value
      : undefined

    const attributes: MessageAttributeMap = {}
    const stickyAttributes: MessageAttributeMap = {}

    Object.keys(sqsAttributes).forEach(key => {
      let cleansedKey: string | undefined
      if (key.startsWith('attributes.')) {
        cleansedKey = key.substr('attributes.'.length)
        attributes[cleansedKey] = getAttributeValue(sqsAttributes, key)
      } else if (key.startsWith('stickyAttributes.')) {
        cleansedKey = key.substr('stickyAttributes.'.length)
github node-ts / bus / packages / bus-core / src / bus-module.ts View on Github external
super(bind => {
      bind(BUS_INTERNAL_SYMBOLS.SessionScopeBinder).toConstantValue(defaultSessionScopeBinder)
      defaultSessionScopeBinder(bind)
      bindLogger(bind, ServiceBus)

      bindService(bind, BUS_SYMBOLS.Transport, MemoryQueue).inSingletonScope()
      bindService(bind, BUS_SYMBOLS.Serializer, JsonSerializer)
      bindService(bind, BUS_SYMBOLS.ApplicationBootstrap, ApplicationBootstrap).inSingletonScope()
      bindService(bind, BUS_SYMBOLS.HandlerRegistry, HandlerRegistry).inSingletonScope()
      bindService(bind, BUS_SYMBOLS.JsonSerializer, JsonSerializer)

      bind(BUS_SYMBOLS.MessageHandlingContext).toConstantValue(new MessageAttributes())
    })
  }

@node-ts/bus-messages

A core set of message definitions for distributed applications.

MIT
Latest version published 9 months ago

Package Health Score

68 / 100
Full package analysis

Popular @node-ts/bus-messages functions