-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed431d7
commit 430116a
Showing
13 changed files
with
811 additions
and
832 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,66 @@ | ||
import { | ||
AuthActionType, | ||
ContextArgs, | ||
QueueConsumer, | ||
} from '@open-template-hub/common'; | ||
import { AuthActionType, ContextArgs, QueueConsumer, } from '@open-template-hub/common'; | ||
|
||
export class AuthQueueConsumer implements QueueConsumer { | ||
private channel: any; | ||
private ctxArgs: ContextArgs = {} as ContextArgs; | ||
|
||
constructor() {} | ||
constructor() { | ||
} | ||
|
||
init = (channel: string, ctxArgs: ContextArgs) => { | ||
init = ( channel: string, ctxArgs: ContextArgs ) => { | ||
this.channel = channel; | ||
this.ctxArgs = ctxArgs; | ||
return this; | ||
}; | ||
|
||
onMessage = async (msg: any) => { | ||
if (msg !== null) { | ||
onMessage = async ( msg: any ) => { | ||
if ( msg !== null ) { | ||
const msgStr = msg.content.toString(); | ||
const msgObj = JSON.parse(msgStr); | ||
const msgObj = JSON.parse( msgStr ); | ||
|
||
const message: AuthActionType = msgObj.message; | ||
|
||
// Decide requeue in the error handling | ||
let requeue = false; | ||
|
||
if (message.example) { | ||
if ( message.example ) { | ||
var exampleHook = async () => { | ||
console.log('Auth server example'); | ||
console.log( 'Auth server example' ); | ||
}; | ||
|
||
await this.operate(msg, msgObj, requeue, exampleHook); | ||
await this.operate( msg, msgObj, requeue, exampleHook ); | ||
} else { | ||
console.log('Message will be rejected: ', msgObj); | ||
this.channel.reject(msg, false); | ||
console.log( 'Message will be rejected: ', msgObj ); | ||
this.channel.reject( msg, false ); | ||
} | ||
} | ||
}; | ||
|
||
private operate = async ( | ||
msg: any, | ||
msgObj: any, | ||
requeue: boolean, | ||
hook: Function | ||
msg: any, | ||
msgObj: any, | ||
requeue: boolean, | ||
hook: Function | ||
) => { | ||
try { | ||
console.log( | ||
'Message Received with deliveryTag: ' + msg.fields.deliveryTag, | ||
msgObj | ||
'Message Received with deliveryTag: ' + msg.fields.deliveryTag, | ||
msgObj | ||
); | ||
await hook(); | ||
await this.channel.ack(msg); | ||
await this.channel.ack( msg ); | ||
console.log( | ||
'Message Processed with deliveryTag: ' + msg.fields.deliveryTag, | ||
msgObj | ||
'Message Processed with deliveryTag: ' + msg.fields.deliveryTag, | ||
msgObj | ||
); | ||
} catch (e) { | ||
} catch ( e ) { | ||
console.log( | ||
'Error with processing deliveryTag: ' + msg.fields.deliveryTag, | ||
msgObj, | ||
e | ||
'Error with processing deliveryTag: ' + msg.fields.deliveryTag, | ||
msgObj, | ||
e | ||
); | ||
|
||
this.channel.nack(msg, false, requeue); | ||
this.channel.nack( msg, false, requeue ); | ||
} | ||
}; | ||
} |
Oops, something went wrong.