Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Event not emitted even though emit() call executed successfully #502

@johnlim

Description

@johnlim

This is a Bug Report

Running this code snippet

module.exports.createUsers = (event, context, callback) => {
  const user = event.data.body;
  if (!user.firstName || !user.lastName || !user.email || !user.id) {
    callback(null, {
      statusCode: 400,
      body: JSON.stringify({errors: [`Invalid request. Missing required field.`]})
    });
    return
  }

  const params = {
    TableName: USERS_EVENT_STORE,
    Item: {
      id: user.id,
      firstName: user.firstName,
      lastName: user.lastName,
      email: user.email,
    }
  };

  eventStore.put(params, (error, result) => {
    if (error) {
      console.error(error);
      callback(null, {
        statusCode: error.statusCode || 501,
        body: JSON.stringify({errors: ['Could not create user']})
      });
      return
    }

    eventGateway
        .emit({
          eventID: '1',
          eventType: 'user.created',
          cloudEventsVersion: '0.1',
          source: '/services/users',
          contentType: 'application/json',
          data: params.Item
        })
        .then(() => console.log('Emitted user.created event'));

    const response = {
      statusCode: 200,
      body: JSON.stringify(params.Item),
    };
    callback(null, response)
  });
};

resulted in the console log Emitted user.created event being captured but the event was not emitted. I know that the event was not emitted because it wasn't captured in the Event Gateway logs (i.e from the Dashboard) and the subscriber function wasn't triggered.

While deploying the console shows that the events were correctly set up as follows:

vent Gateway Plugin
Serverless: WARNING: Inappropriate call of provider.request()
EventGateway: Event Type "user.created" created.
EventGateway: Event Type "http.request" created.
EventGateway: Function "huubhr" registered. (ID: UsersService-dev-huubhr)
EventGateway: Function "createUsers" registered. (ID: dev-UsersService-createUsers)
EventGateway: Function "createUsers" subscribed to "http.request" event.
EventGateway: Function "huubhr" subscribed to "user.created" event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions