-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- feat(faas-adapter+fc-adapter) supports mns topic message queue trig…
…ger, which is enabled by the mode attribute `mode: [mns-topic] `. The sample configuration is as follows: ```yaml mode: [ mns-topic ] malagu: faas-adapter: trigger: invocationRole: acs:ram::123456:role/app-mns-role sourceARN: acs:mns:cn-hangzhou:123456:/topics/test triggerConfig: topicName: test # filterTag: foo ``` - fix(web) replace `alscontext` with `cls-hooked` package to fix `undefined` error. - feat(faas-adapter) adds the `FaaSEventListener` interface, which can be used to monitor the event when the function is triggered to execute.
- Loading branch information
1 parent
5d1c06b
commit c48d2a7
Showing
24 changed files
with
221 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Component } from '@malagu/core'; | ||
import { FaaSEventListener } from './event-protocol'; | ||
|
||
@Component(FaaSEventListener) | ||
export class NoOpEventListener implements FaaSEventListener<{}> { | ||
async onTrigger(event: {}): Promise<void> { | ||
// NoOp | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const FaaSEventListener = Symbol('FaaSEventListener'); | ||
|
||
export interface FaaSEventListener<T> { | ||
onTrigger(event: T): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './event-listener'; | ||
export * from './event-protocol'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './credentials-provider'; | ||
export * from './regin-provider'; | ||
export * from './timer'; | ||
export * from './event'; | ||
export * from './factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './clock'; | ||
export * from './cron-job'; | ||
export * from './timer-protocal'; | ||
export * from './timer-protocol'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
backend: | ||
entry: lib/node/event-application-entry | ||
malagu: | ||
faas-adapter: | ||
function: | ||
runtime: nodejs12 | ||
trigger: | ||
name: ${malagu['faas-adapter'].function.name}-${malagu['faas-adapter'].alias.name}-mns_topic | ||
qualifier: ${malagu['faas-adapter'].alias.name} | ||
functionName: ${malagu['faas-adapter'].function.name} | ||
serviceName: ${malagu['faas-adapter'].service.name} | ||
triggerType: mns_topic | ||
# invocationRole: acs:ram::123456:role/app-mns-role | ||
# sourceARN: acs:mns:cn-hangzhou:123456:/topics/test | ||
triggerConfig: | ||
# topicName: test-topic | ||
notifyContentFormat: JSON | ||
notifyStrategy: BACKOFF_RETRY | ||
# filterTag: foo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { container } from '@malagu/core/lib/common/container/dynamic-container'; | ||
import { Application } from '@malagu/core/lib/common/application/application-protocol'; | ||
import { ContainerProvider } from '@malagu/core/lib/common/container/container-provider'; | ||
import { FaaSEventListener } from '@malagu/faas-adapter/lib/node/event/event-protocol'; | ||
|
||
let listeners: FaaSEventListener<any>[]; | ||
|
||
async function start() { | ||
const c = await container; | ||
ContainerProvider.set(c); | ||
await c.get<Application>(Application).start(); | ||
listeners = c.getAll<FaaSEventListener<any>>(FaaSEventListener); | ||
} | ||
|
||
const startPromise = start(); | ||
|
||
export async function handler(event: string, context: any, callback: any) { | ||
process.env.ALIBABA_ACCOUNT_ID = context.accountId; | ||
process.env.ALIBABA_ACCESS_KEY_ID = context.credentials?.accessKeyId; | ||
process.env.ALIBABA_ACCESS_KEY_SECRET = context.credentials?.accessKeySecret; | ||
process.env.ALIBABA_SECURITY_TOKEN = context.credentials?.securityToken; | ||
process.env.ALIBABA_REQUEST_ID = context.requestId; | ||
process.env.ALIBABA_REGION = context.region; | ||
try { | ||
await startPromise; | ||
await Promise.all(listeners.map(l => l.onTrigger(event))); | ||
callback(); | ||
} catch (error) { | ||
callback(undefined, error); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/lambda-adapter/src/node/event-application-entry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { container } from '@malagu/core/lib/common/container/dynamic-container'; | ||
import { Application } from '@malagu/core/lib/common/application/application-protocol'; | ||
import { ContainerProvider } from '@malagu/core/lib/common/container/container-provider'; | ||
import { FaaSEventListener } from '@malagu/faas-adapter/lib/node/event/event-protocol'; | ||
|
||
let listeners: FaaSEventListener<any>[]; | ||
|
||
async function start() { | ||
const c = await container; | ||
ContainerProvider.set(c); | ||
await c.get<Application>(Application).start(); | ||
listeners = c.getAll<FaaSEventListener<any>>(FaaSEventListener); | ||
} | ||
|
||
const startPromise = start(); | ||
|
||
export async function handler(event: string, context: any, callback: any) { | ||
await startPromise; | ||
await Promise.all(listeners.map(l => l.onTrigger(event))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { container } from '@malagu/core/lib/common/container/dynamic-container'; | ||
import { Application } from '@malagu/core/lib/common/application/application-protocol'; | ||
import { ContainerProvider } from '@malagu/core/lib/common/container/container-provider'; | ||
import { Clock } from '@malagu/faas-adapter/lib/node/timer/timer-protocal'; | ||
import { Clock } from '@malagu/faas-adapter/lib/node/timer/timer-protocol'; | ||
import { FaaSEventListener } from '@malagu/faas-adapter/lib/node/event/event-protocol'; | ||
|
||
let clock: Clock; | ||
let listeners: FaaSEventListener<any>[]; | ||
|
||
async function start() { | ||
const c = await container; | ||
ContainerProvider.set(c); | ||
await c.get<Application>(Application).start(); | ||
clock = c.get<Clock>(Clock); | ||
listeners = c.getAll<FaaSEventListener<any>>(FaaSEventListener); | ||
} | ||
|
||
const startPromise = start(); | ||
|
||
export async function handler(event: string, context: any) { | ||
await startPromise; | ||
await Promise.all(listeners.map(l => l.onTrigger(event))); | ||
return clock.tick(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { container } from '@malagu/core/lib/common/container/dynamic-container'; | ||
import { Application } from '@malagu/core/lib/common/application/application-protocol'; | ||
import { ContainerProvider } from '@malagu/core/lib/common/container/container-provider'; | ||
import { FaaSEventListener } from '@malagu/faas-adapter/lib/node/event/event-protocol'; | ||
|
||
let listeners: FaaSEventListener<any>[]; | ||
|
||
async function start() { | ||
const c = await container; | ||
ContainerProvider.set(c); | ||
await c.get<Application>(Application).start(); | ||
listeners = c.getAll<FaaSEventListener<any>>(FaaSEventListener); | ||
} | ||
|
||
const startPromise = start(); | ||
|
||
export async function handler(event: string, context: any, callback: any) { | ||
await startPromise; | ||
await Promise.all(listeners.map(l => l.onTrigger(event))); | ||
context.callbackWaitsForEmptyEventLoop = false; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.