This repository was archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Event not emitted even though emit() call executed successfully #502
Copy link
Copy link
Open
Description
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
Labels
No labels