-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
206 additions
and
6 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,5 +1,7 @@ | ||
import actionsGenerator from './actionsGenerator'; | ||
|
||
export const actionsDict = actionsGenerator(); | ||
|
||
export default { | ||
actionsDict:actionsGenerator(), | ||
actionsDict, | ||
} |
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,7 @@ | ||
import makeType from '../utils/makeType'; | ||
|
||
export const SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION = makeType('SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION'); | ||
export const SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION_RES = makeType('SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION_RES'); | ||
|
||
export const CONSUME_FROM_QUEUE_OF_ONE_SESSION = makeType('CONSUME_FROM_QUEUE_OF_ONE_SESSION'); | ||
export const CONSUME_FROM_QUEUE_OF_ONE_SESSION_RES = makeType('CONSUME_FROM_QUEUE_OF_ONE_SESSION_RES'); |
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,18 @@ | ||
import { Action } from 'redux-actions'; | ||
import createFSA, { ActionCreator } from '../utils/createFSA'; | ||
|
||
import * as types from './types'; | ||
import * as actionTypes from './actions.constant'; | ||
|
||
export const sendOneTxtMsgToQueueOfOneSession:ActionCreator<types.ISendOneTxtMsgToQueueOfOneSessionPayload> = | ||
createFSA<types.ISendOneTxtMsgToQueueOfOneSessionPayload>( | ||
actionTypes.SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION, | ||
(options:types.ISendOneTxtMsgToQueueOfOneSessionPayload) => <any> options | ||
); | ||
|
||
|
||
export const consumeFromQueueOfOneSession:ActionCreator<types.IConsumeFromQueueOfOneSessionPayload> = | ||
createFSA<types.IConsumeFromQueueOfOneSessionPayload>( | ||
actionTypes.CONSUME_FROM_QUEUE_OF_ONE_SESSION, | ||
(options:types.IConsumeFromQueueOfOneSessionPayload) => <any> options | ||
); |
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,99 @@ | ||
import {Action} from 'redux-actions'; | ||
|
||
import { initState, dispatchAction } from '../init'; | ||
import msgBuilder, {IMsgBuilt} from '../utils/msgBuilder'; | ||
|
||
import { actionsDict as EventActions } from '../event' | ||
|
||
import * as types from "./types"; | ||
import * as handlerActions from './handlerActions'; | ||
|
||
const SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION_ERR_MSG='[redux-solace] Failed to send one txt msg to queue of one session'; | ||
const CONSUME_FROM_QUEUE_OF_ONE_SESSION_ERR_MSG='[redux-solace] Failed to consume from queue of one session'; | ||
|
||
|
||
export async function sendOneTxtMsgToQueueOfOneSession(action:Action<types.ISendOneTxtMsgToQueueOfOneSessionPayload>) | ||
:Promise<Action<types.ISendOneTxtMsgToQueueOfOneSessionResPayload>> | ||
{ | ||
const { | ||
sessionId, queueName, msgTxt, userDataStr, userPropertyMap, correlationKey | ||
} = action.payload; | ||
|
||
try{ | ||
initState.solaceContext.sendOneTxtMsgToQueueOfOneSession( | ||
sessionId, queueName, msgTxt, userDataStr, userPropertyMap, correlationKey, | ||
); | ||
const responoseAction = handlerActions.sendOneTxtMsgToQueueOfOneSessionRes({ | ||
sessionId, queueName, msgTxt, userDataStr, userPropertyMap, correlationKey, | ||
}); | ||
dispatchAction(responoseAction); | ||
return responoseAction; | ||
}catch (e) { | ||
console.error(e.message); | ||
dispatchAction(handlerActions.sendOneTxtMsgToQueueOfOneSessionRes({ | ||
name:SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION_ERR_MSG, | ||
error:e, | ||
})); | ||
throw e; | ||
} | ||
|
||
} | ||
|
||
export async function consumeFromQueueOfOneSession(action:Action<types.IConsumeFromQueueOfOneSessionPayload>) | ||
:Promise<Action<types.IConsumeFromQueueOfOneSessionResPayload>> | ||
{ | ||
const { | ||
sessionId, queueName, autoAcknowledge, otherCallbackDict, | ||
} = action.payload; | ||
|
||
const onMsgCb = (sessionEvent)=>{ | ||
const result = msgBuilder(sessionEvent); | ||
dispatchAction( | ||
EventActions[initState.solace.MessageConsumerEventName.MESSAGE] | ||
.action({ | ||
sessionId, queueName, | ||
...result, | ||
}) | ||
) | ||
}; | ||
|
||
const wrappedCbDict:{[key:number]:Function,[key:string]:Function} ={}; | ||
|
||
initState.solaceContext.messageConsumerEventCodes.forEach((oneEventCode)=>{ | ||
if (oneEventCode !== initState.solace.MessageConsumerEventName.MESSAGE){ | ||
if (otherCallbackDict && otherCallbackDict[oneEventCode]){ | ||
wrappedCbDict[oneEventCode] = function () { | ||
dispatchAction(EventActions[oneEventCode].action({ | ||
sessionId, queueName, arguments | ||
})); | ||
return otherCallbackDict[oneEventCode](); | ||
} | ||
}else{ | ||
wrappedCbDict[oneEventCode] = function () { | ||
dispatchAction(EventActions[oneEventCode].action({ | ||
sessionId, queueName, arguments | ||
})); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
try{ | ||
initState.solaceContext.consumeFromQueueOfOneSession( | ||
sessionId, queueName, onMsgCb, autoAcknowledge, wrappedCbDict, | ||
); | ||
const responoseAction = handlerActions.consumeFromQueueOfOneSessionRes({ | ||
sessionId, queueName | ||
}); | ||
dispatchAction(responoseAction); | ||
return responoseAction; | ||
}catch (e) { | ||
console.error(e.message); | ||
dispatchAction(handlerActions.consumeFromQueueOfOneSessionRes({ | ||
name:CONSUME_FROM_QUEUE_OF_ONE_SESSION_ERR_MSG, | ||
error:e, | ||
})); | ||
throw e; | ||
} | ||
|
||
} |
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,18 @@ | ||
import { Action } from 'redux-actions'; | ||
import createFSA, { ActionCreator } from '../utils/createFSA'; | ||
|
||
import * as types from './types'; | ||
import * as actionTypes from './actions.constant'; | ||
|
||
export const sendOneTxtMsgToQueueOfOneSessionRes:ActionCreator<types.ISendOneTxtMsgToQueueOfOneSessionResPayload> = | ||
createFSA<types.ISendOneTxtMsgToQueueOfOneSessionResPayload>( | ||
actionTypes.SEND_ONE_TXT_MSG_TO_QUEUE_OF_ONE_SESSION_RES, | ||
(options:types.ISendOneTxtMsgToQueueOfOneSessionResPayload) => <any> options | ||
); | ||
|
||
|
||
export const consumeFromQueueOfOneSessionRes:ActionCreator<types.IConsumeFromQueueOfOneSessionResPayload> = | ||
createFSA<types.IConsumeFromQueueOfOneSessionResPayload>( | ||
actionTypes.CONSUME_FROM_QUEUE_OF_ONE_SESSION_RES, | ||
(options:types.IConsumeFromQueueOfOneSessionResPayload) => <any> options | ||
); |
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,16 @@ | ||
import {ActionHandlerParams} from "../GlobalTypes"; | ||
import * as asyncs from './async'; | ||
|
||
export const sendOneTxtMsgToQueueOfOneSessionHanlder = (params:ActionHandlerParams)=>{ | ||
const { action } = params; | ||
asyncs.sendOneTxtMsgToQueueOfOneSession(action).catch( e=>{ | ||
// eat the exception | ||
}) | ||
} | ||
|
||
export const consumeFromQueueOfOneSessionHanlder = (params:ActionHandlerParams)=>{ | ||
const { action } = params; | ||
asyncs.consumeFromQueueOfOneSession(action).catch( e=>{ | ||
// eat the exception | ||
}) | ||
} |
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,29 @@ | ||
import { BaseRequestPayload, BaseResponsePayload } from '../base/BasePayload'; | ||
|
||
export interface ISendOneTxtMsgToQueueOfOneSessionPayload extends BaseRequestPayload{ | ||
sessionId:string, | ||
queueName:string, | ||
msgTxt:string, | ||
userDataStr?:string, | ||
userPropertyMap?:any, | ||
correlationKey?:any, | ||
} | ||
export interface ISendOneTxtMsgToQueueOfOneSessionResPayload extends BaseResponsePayload{ | ||
sessionId?:string, | ||
queueName?:string, | ||
msgTxt?:string, | ||
userDataStr?:string, | ||
userPropertyMap?:any, | ||
correlationKey?:any, | ||
} | ||
|
||
export interface IConsumeFromQueueOfOneSessionPayload extends BaseRequestPayload{ | ||
sessionId:string, | ||
queueName:string, | ||
autoAcknowledge?:boolean, | ||
otherCallbackDict?:{[key:number]:Function,[key:string]:Function}, | ||
} | ||
export interface IConsumeFromQueueOfOneSessionResPayload extends BaseResponsePayload{ | ||
sessionId?:string, | ||
queueName?:string, | ||
} |
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