Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: node-ts/bus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f3eb2e8fb6c812d764fcc0e49b04d493bc36d665
Choose a base ref
...
head repository: node-ts/bus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 82997a83eeeff6e27b55d89373c91a202b1e590b
Choose a head ref
  • 16 commits
  • 59 files changed
  • 2 contributors

Commits on May 31, 2020

  1. use latest pg package

    adenhertog committed May 31, 2020
    Copy the full SHA
    b7bf030 View commit details
  2. Publish

     - @node-ts/bus-postgres@0.4.4
    adenhertog committed May 31, 2020
    Copy the full SHA
    dab44de View commit details

Commits on Jun 2, 2020

  1. Squashed commit of the following:

    commit ae945ff1cd1b8c3f36130fec2ceb1e26f221c0c3
    Author: Andrew den Hertog <andrew.denhertog@gmail.com>
    Date:   Tue Jun 2 15:16:46 2020 +1000
    
        add hooks
    adenhertog committed Jun 2, 2020
    Copy the full SHA
    17bc292 View commit details
  2. Publish

     - @node-ts/bus-core@0.5.4
     - @node-ts/bus-postgres@0.4.5
     - @node-ts/bus-rabbitmq@0.5.3
     - @node-ts/bus-sqs@0.4.4
     - @node-ts/bus-workflow@0.5.4
    adenhertog committed Jun 2, 2020
    Copy the full SHA
    7e4102d View commit details
  3. Copy the full SHA
    6c8cb74 View commit details
  4. Publish

     - @node-ts/bus-core@0.5.5
     - @node-ts/bus-postgres@0.4.6
     - @node-ts/bus-rabbitmq@0.5.4
     - @node-ts/bus-sqs@0.4.5
     - @node-ts/bus-workflow@0.5.5
    adenhertog committed Jun 2, 2020
    Copy the full SHA
    f0a185b View commit details
  5. await hooks

    adenhertog committed Jun 2, 2020
    Copy the full SHA
    afe832e View commit details
  6. Publish

     - @node-ts/bus-core@0.5.6
     - @node-ts/bus-postgres@0.4.7
     - @node-ts/bus-rabbitmq@0.5.5
     - @node-ts/bus-sqs@0.4.6
     - @node-ts/bus-workflow@0.5.6
    adenhertog committed Jun 2, 2020
    Copy the full SHA
    6d21eab View commit details
  7. Copy the full SHA
    e3429dd View commit details
  8. Publish

     - @node-ts/bus-core@0.5.7
     - @node-ts/bus-postgres@0.4.8
     - @node-ts/bus-rabbitmq@0.5.6
     - @node-ts/bus-sqs@0.4.7
     - @node-ts/bus-workflow@0.5.7
    adenhertog committed Jun 2, 2020
    Copy the full SHA
    499d3f9 View commit details

Commits on Jun 10, 2020

  1. Copy the full SHA
    737ab0d View commit details
  2. Publish

     - @node-ts/bus-core@0.5.8
     - @node-ts/bus-postgres@0.4.9
     - @node-ts/bus-rabbitmq@0.5.7
     - @node-ts/bus-sqs@0.4.8
     - @node-ts/bus-workflow@0.5.8
    adenhertog committed Jun 10, 2020
    Copy the full SHA
    14787de View commit details

Commits on Jun 15, 2020

  1. Allow SQS Transport to use Bus.Serializer to (de)serialization (#73)

    * Allow SQS Transport to use BUS.Serializer to (de)serialization
    
    * remove handlerRegistry dependency from Transport.initialize function params
    
    * recover package.json
    
    * recover package.json
    
    * PR feedbacks
    zhming0 authored Jun 15, 2020
    Copy the full SHA
    c6eb46c View commit details
  2. Publish

     - @node-ts/bus-core@0.5.9
     - @node-ts/bus-postgres@0.4.10
     - @node-ts/bus-rabbitmq@0.5.8
     - @node-ts/bus-sqs@0.4.9
     - @node-ts/bus-workflow@0.5.9
    adenhertog committed Jun 15, 2020
    Copy the full SHA
    895bdd8 View commit details

Commits on Jul 12, 2020

  1. Explicitly fail messages (#75)

    * fail messages for rabbitmq
    
    * fail message for memory queue
    
    * memory queue fail tests
    
    * fail sqs messages
    
    * SQS fail message implementation
    
    * fix routing of sqs fail messages
    
    * remove unused imports
    
    * minor test fixes
    
    * correct naming in serializers
    
    * correct naming in serializers
    
    * upgrade circle runner to node 12
    
    * upgrade typescript and fix broken types
    
    * set snyk badge
    
    * doc updates
    
    * fail message attribute tests
    
    * unfocus tests
    adenhertog authored Jul 12, 2020
    Copy the full SHA
    6c350eb View commit details
  2. Publish

     - @node-ts/bus-core@0.6.0
     - @node-ts/bus-messages@0.3.0
     - @node-ts/bus-postgres@0.5.0
     - @node-ts/bus-rabbitmq@0.6.0
     - @node-ts/bus-sqs@0.5.0
     - @node-ts/bus-workflow@0.6.0
    adenhertog committed Jul 12, 2020
    Copy the full SHA
    82997a8 View commit details
Showing with 2,872 additions and 1,156 deletions.
  1. +1 −1 .circleci/config.yml
  2. +1 −1 .nvmrc
  3. +8 −7 package.json
  4. +28 −3 packages/bus-core/README.md
  5. +2 −2 packages/bus-core/package.json
  6. +1 −2 packages/bus-core/src/application-bootstrap/application-bootstrap.ts
  7. +4 −2 packages/bus-core/src/bus-module.ts
  8. +4 −1 packages/bus-core/src/bus-symbols.ts
  9. +20 −0 packages/bus-core/src/error/fail-message-outside-handling-context.ts
  10. +1 −0 packages/bus-core/src/error/index.ts
  11. +23 −0 packages/bus-core/src/handler/handler-registry.spec.ts
  12. +17 −0 packages/bus-core/src/handler/handler-registry.ts
  13. +1 −0 packages/bus-core/src/index.ts
  14. +1 −0 packages/bus-core/src/serialization/index.ts
  15. +10 −6 packages/bus-core/src/serialization/json-serializer.ts
  16. +74 −0 packages/bus-core/src/serialization/message-serializer.spec.ts
  17. +40 −0 packages/bus-core/src/serialization/message-serializer.ts
  18. +15 −2 packages/bus-core/src/serialization/serializer.ts
  19. +49 −0 packages/bus-core/src/service-bus/bus-hooks.spec.ts
  20. +34 −0 packages/bus-core/src/service-bus/bus-hooks.ts
  21. +42 −1 packages/bus-core/src/service-bus/bus.ts
  22. +2 −0 packages/bus-core/src/service-bus/index.ts
  23. +13 −0 packages/bus-core/src/service-bus/message-handling-context.ts
  24. +48 −6 packages/bus-core/src/service-bus/service-bus.integration.ts
  25. +48 −23 packages/bus-core/src/service-bus/service-bus.ts
  26. +2 −0 packages/bus-core/src/test/index.ts
  27. +7 −0 packages/bus-core/src/test/test-event-2.ts
  28. +13 −0 packages/bus-core/src/test/test-fail-message.ts
  29. +1 −1 packages/bus-core/src/transport/index.ts
  30. +49 −8 packages/bus-core/src/transport/memory-queue.spec.ts
  31. +64 −18 packages/bus-core/src/transport/memory-queue.ts
  32. +8 −4 packages/bus-core/src/transport/transport.ts
  33. +1 −1 packages/bus-messages/README.md
  34. +1 −1 packages/bus-messages/package.json
  35. +2 −2 packages/bus-postgres/README.md
  36. +6 −6 packages/bus-postgres/package.json
  37. +1 −1 packages/bus-rabbitmq/README.md
  38. +3 −3 packages/bus-rabbitmq/package.json
  39. +54 −4 packages/bus-rabbitmq/src/rabbitmq-transport.integration.ts
  40. +24 −9 packages/bus-rabbitmq/src/rabbitmq-transport.ts
  41. +2 −0 packages/bus-rabbitmq/test/index.ts
  42. +16 −0 packages/bus-rabbitmq/test/test-fail-message-handler.ts
  43. +13 −0 packages/bus-rabbitmq/test/test-fail-message.ts
  44. +4 −2 packages/bus-sqs/README.md
  45. +4 −3 packages/bus-sqs/package.json
  46. +6 −0 packages/bus-sqs/src/sqs-transport-configuration.ts
  47. +77 −22 packages/bus-sqs/src/sqs-transport.integration.ts
  48. +38 −9 packages/bus-sqs/src/sqs-transport.ts
  49. +2 −0 packages/bus-sqs/test/index.ts
  50. +8 −1 packages/bus-sqs/test/test-command.ts
  51. +16 −0 packages/bus-sqs/test/test-fail-message-handler.ts
  52. +13 −0 packages/bus-sqs/test/test-fail-message.ts
  53. +1 −1 packages/bus-workflow/README.md
  54. +3 −3 packages/bus-workflow/package.json
  55. +12 −6 packages/bus-workflow/src/workflow/decorators/handles.ts
  56. +1 −1 packages/bus-workflow/src/workflow/message-workflow-mapping.ts
  57. +1 −1 packages/bus-workflow/src/workflow/persistence/in-memory-persistence.ts
  58. +4 −0 test.env
  59. +1,928 −992 yarn.lock
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:8.14.1
- image: circleci/node:12.18.1

jobs:
build:
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.15.0
12.14.1
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@
"docs:deploy": "./deploy-docs.sh",
"lint": "lerna run lint",
"test": "yarn test:unit && yarn test:integration",
"test:unit": "jest \"(src\\/.+\\.|/)spec\\.ts$\"",
"test:unit": "dotenv -e test.env -- jest \"(src\\/.+\\.|/)spec\\.ts$\"",
"test:unit:watch": "yarn run test:unit --watch",
"test:integration": "jest --runInBand \"bus-(core|messages|workflow).*(src\\/.+\\.|/)integration\\.ts$\""
"test:integration": "dotenv -e test.env -- jest --runInBand \"bus-(core|messages|workflow).*(src\\/.+\\.|/)integration\\.ts$\""
},
"keywords": [
"typescript",
@@ -44,14 +44,15 @@
],
"devDependencies": {
"@node-ts/code-standards": "^0.0.10",
"@types/jest": "^24.0.12",
"@types/jest": "^26.0.4",
"dotenv-cli": "^3.2.0",
"inversify": "^5.0.1",
"jest": "^24.7.1",
"jest": "^26.1.0",
"lerna": "^3.18.4",
"reflect-metadata": "^0.1.13",
"ts-jest": "^25.1.0",
"tslib": "^1.9.3",
"typescript": "^3.3.3",
"ts-jest": "^26.1.1",
"tslib": "^2.0.0",
"typescript": "^3.9.6",
"vuepress": "^1.1.0",
"vuepress-plugin-sitemap": "^2.1.2"
}
31 changes: 28 additions & 3 deletions packages/bus-core/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @node-ts/bus-core

[![Greenkeeper badge](https://badges.greenkeeper.io/node-ts/bus.svg)](https://greenkeeper.io/)
[![Known Vulnerabilities](https://snyk.io/test/github/node-ts/bus/badge.svg)](https://snyk.io/test/github/node-ts/bus)
[![CircleCI](https://circleci.com/gh/node-ts/bus/tree/master.svg?style=svg)](https://circleci.com/gh/node-ts/bus/tree/master)[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

The core messaging framework. This package provides an in-memory queue and persistence by default, but is designed to be used with other @node-ts/bus-* packages that provide compatibility with other transports (SQS, RabbitMQ, Azure Queues) and persistence technologies (PostgreSQL, SQL Server, Oracle).
@@ -29,7 +29,7 @@ export class ApplicationContainer extends Container {

## Register a message handler

Messages are handled by defining and registring a handler class. Each time a message is received by the application, it will be dispatched to each of the registered handlers.
Messages are handled by defining and registering a handler class. Each time a message is received by the application, it will be dispatched to each of the registered handlers.

Define the handler:

@@ -87,4 +87,29 @@ export class Application {
await this.bus.stop()
}
}
```
```

## Hooks

Hooks are callback functions that are invoked each time an action occurs. These are commonly used to add in testing, logging or health probes centrally to the application.

Hooks can be added by calling `.on()` on the bus. For example, to trigger a callback each time a message is attempted to be sent, use:

```typescript
addHook (): void {
const bus = this.container.get<Bus>(BUS_SYMBOLS.Bus)
const callback = message => console.log('Sending', JSON.stringify(message))
bus.on('send', callback)

// To remove the above hook, call bus.off():
bus.off('send', callback)
}
```

## Failing a Message

When an error is thrown whilst handling an error, the message is typically sent back to the queue so that it can be retried.

There are times when we know that a message will never succeed even if it were to be retried. In these situations we may not want to wait for our message to be retried before sending it to the dead letter queue, but instead bypass the retries and send it to the dead letter queue immediately.

This can be done by calling `bus.fail()` from within the scope of a message handling context. This will instruct `@node-ts/bus` to forward the currently handled message to the dead letter queue and remove it from the service queue.
4 changes: 2 additions & 2 deletions packages/bus-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-ts/bus-core",
"version": "0.5.3",
"version": "0.6.0",
"description": "A service bus for message-based, distributed node applications",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
@@ -13,7 +13,7 @@
"access": "public"
},
"dependencies": {
"@node-ts/bus-messages": "^0.2.3",
"@node-ts/bus-messages": "^0.3.0",
"@types/node": "^12.12.37",
"autobind-decorator": "^2.4.0",
"class-transformer": "^0.2.3",
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Message } from '@node-ts/bus-messages'
import { LOGGER_SYMBOLS, Logger } from '@node-ts/logger-core'
import { Container, inject, injectable } from 'inversify'
import { BUS_SYMBOLS } from '../bus-symbols'
@@ -86,7 +85,7 @@ export class ApplicationBootstrap {

private async initializeTransport (): Promise<void> {
if (this.transport.initialize) {
await this.transport.initialize(this.handlerRegistry)
await this.transport.initialize()
}
}
}
6 changes: 4 additions & 2 deletions packages/bus-core/src/bus-module.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ import { ContainerModule, interfaces } from 'inversify'
import { BUS_SYMBOLS, BUS_INTERNAL_SYMBOLS } from './bus-symbols'
import { MessageAttributes } from '@node-ts/bus-messages'
import { MemoryQueue } from './transport'
import { ServiceBus } from './service-bus'
import { JsonSerializer } from './serialization'
import { ServiceBus, BusHooks } from './service-bus'
import { JsonSerializer, MessageSerializer } from './serialization'
import { ApplicationBootstrap } from './application-bootstrap'
import { HandlerRegistry } from './handler'
import { ClassConstructor } from './util'
@@ -27,6 +27,8 @@ export class BusModule extends ContainerModule {
bindService(bind, BUS_SYMBOLS.ApplicationBootstrap, ApplicationBootstrap).inSingletonScope()
bindService(bind, BUS_SYMBOLS.HandlerRegistry, HandlerRegistry).inSingletonScope()
bindService(bind, BUS_SYMBOLS.JsonSerializer, JsonSerializer)
bindService(bind, BUS_SYMBOLS.MessageSerializer, MessageSerializer)
bindService(bind, BUS_INTERNAL_SYMBOLS.BusHooks, BusHooks).inSingletonScope()

bind(BUS_SYMBOLS.MessageHandlingContext).toConstantValue(new MessageAttributes())
})
5 changes: 4 additions & 1 deletion packages/bus-core/src/bus-symbols.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,12 @@ export const BUS_SYMBOLS = {
HandlerRegistry: Symbol.for('@node-ts/bus-core/handler-registry'),
ApplicationBootstrap: Symbol.for('@node-ts/bus-core/application-bootstrap'),
JsonSerializer: Symbol.for('@node-ts/bus-core/json-serializer'),
MessageSerializer: Symbol.for('@node-ts/bus-core/message-serializer'),
MessageHandlingContext: Symbol.for('@node-ts/bus-core/message-handling-context')
}

export const BUS_INTERNAL_SYMBOLS = {
SessionScopeBinder: Symbol.for('@node-ts/bus-core/session-scope-binder')
SessionScopeBinder: Symbol.for('@node-ts/bus-core/session-scope-binder'),
BusHooks: Symbol.for('@node-ts/bus-core/bus-hooks'),
RawMessage: Symbol.for('@node-ts/bus-core/raw-message')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Message } from '@node-ts/bus-messages'

export class FailMessageOutsideHandlingContext extends Error {
/**
* Calling .fail() with a message indicates that the message received from the
* queue can not be processed even with retries and should immediately be sent
* to the dead letter queue.
*
* This error occurs when .fail() has been called outside of a message handling context,
* or more specifically - outside the stack of a Handler() operation
* @param msg The message that was attempted to be failed
*/
constructor (
readonly msg: Message
) {
super(`Attempted to fail message outside of a message handling context`)
// tslint:disable-next-line:no-unsafe-any
Object.setPrototypeOf(this, new.target.prototype)
}
}
1 change: 1 addition & 0 deletions packages/bus-core/src/error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './fail-message-outside-handling-context'
23 changes: 23 additions & 0 deletions packages/bus-core/src/handler/handler-registry.spec.ts
Original file line number Diff line number Diff line change
@@ -122,4 +122,27 @@ describe('HandlerRegistry', () => {
})
})

describe('when getting a messageType', () => {

beforeEach(() => {
sut.register((m: Message) => m.$name === messageName, symbol, handler, messageType)
})

it('return msg constructor when found', () => {
const msg = {
$name: TestEvent.NAME
}
const result = sut.getMessageType(msg as Message)
expect(result).toBe(TestEvent)
})

it('return undefined when not found', () => {
const msg = {
$name: 'bluhbluh-very-important-command'
}
const result = sut.getMessageType(msg as Message)
expect(result).toBeUndefined()
})
})

})
17 changes: 17 additions & 0 deletions packages/bus-core/src/handler/handler-registry.ts
Original file line number Diff line number Diff line change
@@ -117,6 +117,23 @@ export class HandlerRegistry {
}))
}

/**
* Gets the type consturctor for a given message name.
* This is used for deserialization
* @param message A message instance to resolve handlers for
*/
getMessageType<TMessage extends MessageType> (message: TMessage): HandlerResolver['messageType'] {
const resolvedHandlers = this.handlerResolvers
.filter(resolvers => resolvers.resolver(message))

if (resolvedHandlers.length === 0) {
return undefined
}

// Assuming one message name is only associated with one message type
return resolvedHandlers[0].messageType
}

/**
* Binds message handlers into the IoC container. All handlers should be stateless and are
* bound in a transient scope.
1 change: 1 addition & 0 deletions packages/bus-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -6,3 +6,4 @@ export * from './application-bootstrap'
export * from './handler'
export * from './serialization'
export * from './util'
export * from './error'
1 change: 1 addition & 0 deletions packages/bus-core/src/serialization/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './serializer'
export * from './json-serializer'
export * from './message-serializer'
16 changes: 10 additions & 6 deletions packages/bus-core/src/serialization/json-serializer.ts
Original file line number Diff line number Diff line change
@@ -4,18 +4,22 @@ import { ClassConstructor } from '../util'
import { classToPlain, plainToClass, serialize, deserialize } from 'class-transformer'

/**
* A very unsafe, basic JSON serializer. This will serialize objects to strings, but will
* deserialize strings into plain objects. These will NOT contain methods or special types,
* so the usage of this serializer is limited.
* A JSON-based serializer that uses `class-transformer` to transform to and from
* class instances of an object rather than just their plain types. As a result,
* object types can use all of the serialization decorator hints provided by
* that library.
*/
@injectable()
export class JsonSerializer implements Serializer {
serialize<T extends object> (obj: T): string {
serialize<ObjectType extends object> (obj: ObjectType): string {
return serialize(obj)
}

deserialize<T extends object> (val: string, classConstructor: ClassConstructor<T>): T {
return deserialize<T> (classConstructor, val)
deserialize<ObjectType extends object> (
serialized: string,
classConstructor: ClassConstructor<ObjectType>
): ObjectType {
return deserialize<ObjectType> (classConstructor, serialized)
}

toPlain<T extends object> (obj: T): object {
74 changes: 74 additions & 0 deletions packages/bus-core/src/serialization/message-serializer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// tslint:disable:max-classes-per-file no-inferred-empty-object-type
import { Serializer } from './serializer'
import { ClassConstructor } from '../util'
import { MessageSerializer } from './message-serializer'
import { Mock, IMock, It } from 'typemoq'
import { HandlerRegistry } from '../handler'
import * as faker from 'faker'
import { Message } from '@node-ts/bus-messages'

class DummyMessage {
$name = 'bluh'
$version = 1
value: string

constructor (s: string) {
this.value = s
}
}

class ToxicSerializer implements Serializer {

serialize<ObjectType extends object> (obj: ObjectType): string {
return (obj as Message).$name
}

deserialize<ObjectType extends object> (serialized: string, classType: ClassConstructor<ObjectType>): ObjectType {
return new classType(serialized)
}
}

describe('MessageSerializer', () => {

let sut: MessageSerializer
let handlerRegistry: IMock<HandlerRegistry>
const msgName = 'dummy-message'

beforeEach(() => {
handlerRegistry = Mock.ofType<HandlerRegistry>()
handlerRegistry.setup(h => h.getMessageType(
It.isObjectWith({
$name: msgName
})
)).returns(() => DummyMessage)

const toxicSerializer = new ToxicSerializer()

sut = new MessageSerializer(
toxicSerializer,
handlerRegistry.object
)
})

it('should use underlying serializer to serialize', () => {
const message: Message = {
$name: msgName,
$version: 1
}
const result = sut.serialize(message)
expect(result).toBe(message.$name)
})

it('should use underlying deserializer to deserialize', () => {
const msg = {
$name: msgName,
text: faker.random.words()
}
const raw = JSON.stringify(msg)

const result = sut.deserialize<DummyMessage>(raw)

handlerRegistry.verifyAll()
expect(result.value).toBe(raw)
})
})
40 changes: 40 additions & 0 deletions packages/bus-core/src/serialization/message-serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { injectable, inject } from 'inversify'
import { Serializer } from './serializer'
import { BUS_SYMBOLS } from '../bus-symbols'
import { HandlerRegistry } from '../handler'
import { Message } from '@node-ts/bus-messages'

/**
* This a wrapper around the real serializer.
* Unlike JsonSerializer, whose sole job is parsing data,
* this class will do some plumbing work to look up the Handler Registry for
* the message constructor.
*
* Normally, transports will use this instead of the real serializer.
*/
@injectable()
export class MessageSerializer {

constructor (
@inject(BUS_SYMBOLS.Serializer)
readonly serializer: Serializer,
@inject(BUS_SYMBOLS.HandlerRegistry)
readonly handlerRegistry: HandlerRegistry
) {
}

serialize<MessageType extends Message> (message: MessageType): string {
return this.serializer.serialize(message)
}

deserialize<MessageType extends Message> (serializedMessage: string): MessageType {
const naiveDerializedMessage = JSON.parse(serializedMessage) as Message
const messageType = this.handlerRegistry.getMessageType(naiveDerializedMessage)

return (!!messageType
? this.serializer.deserialize(
serializedMessage,
messageType
) : naiveDerializedMessage) as MessageType
}
}
Loading