Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

solace redux middleware wrapper

License

NotificationsYou must be signed in to change notification settings

albertleigh/redux-solace

Repository files navigation

versionlicense

Redux-solace wraps the solace js library into a reusable redux middleware

  • It is designed for browser runtime only, not for node js runtime
  • Written in Typescript
  • Provide promise based Apis
  • Provide flux action based Apis
  • All action parameters follow the Redux/FLUX pattern
  • Wrap solace api into one core class
  • Support Multi-session management
  • Support Publish/Subscribe to topics
  • Support Queue msg
  • Support request/reply msg

Documentation

Quick start

Install

    npm install redux-solace -S        -- or         yarn add redux-solace

Build the middleware and inject into store

User thecreateSolaceMiddleware to create one middleware and add it to middleware chain.

import{createSolaceMiddleware}from'redux-solace'constsolaceMiddleware=createSolaceMiddleware();constmiddleware=compose(applyMiddleware(sagaMiddleware,solaceMiddleware),devtools);conststore=createStore(rootReducer,middleware)

Then inject the store into your frontend freawer like (React, Angular 5/6/7)

conststore=configureStore();store.dispatch(applicationStarted());ReactDom.render(<React.Fragment><Providerstore={store}><App/></Provider></React.Fragment>);

All set

Make no mistake , you are now good to connect to the solace message router.

// import the session package and rename it if neededimport{SessionasSolaceSession}from'redux-solace';function*createOneSolaceSession(){conststate=yieldselect(getSession);yieldput(SolaceSession.actions.createAndConnectSession({hostUrl:state.newSessionHostUrl,vpn:state.newSessionVpn,username:state.newSessionUsername,sessionCache:state.newSessionCache,pass:state.newSessionPass,config:{usePerMsgAck:state.newSessionUsePerMsgAck,}}))}exportdefaultfunction*(){yieldtakeLatest(SESSION_SUBMIT_NEW,createOneSolaceSession);}

sample response action object

    {"type":"REDUX_SOLACE::CREATE_AND_CONNECT_SESSION_RES","payload": {"result": {"id":"9401a90b-b4e3-4987-9910-3ed9d7b3ff","name":"Session-0","session": {...}// native solace session object"config": {"usePerMsgAck":false            },"subscribedTopics": [],"consumeDict": {},"createdAt":new Date(15326723722)          }      },"error":false          }

Response action could be listened like

import{SessionasSolaceSession}from'redux-solace';function*handleSolaceSessionResponse(action){// if there were any errors while creating the session, the action.error would be the error objif(!action.error){yieldput(applicationNewSnackbar({message:`${action.payload.result.name} created`}))}}exportdefaultfunction*(){yieldtakeLatest(SolaceSession.actions.CREATE_AND_CONNECT_SESSION_RES,handleSolaceSessionResponse);}

or aSOLACE_CONTEXT_CHANGED action will be also emitted if sessions changed

import{handleActions}from'redux-actions';import{SessionasSolaceSession}from'redux-solace';constdefaultState={...};exportdefaulthandleActions({[SolaceSession.actions.SOLACE_CONTEXT_CHANGED]:(state,action)=>{const{                total,                defaultSessionId,                sessionContexts}=action.payload;return{                ...state,                total,                defaultSessionId,sessions:sessionContexts,}}})

Performance

A benchmark pressure test has been conducted along with a original solution using delegate server connecting solace router via websocket(socket.io).The conclusion is, using redux-solace will be 10-30ms slower on average per message than original solution using delegate server,but redux-solace brings flexibility, avoids delegate sever preprocess or schema negotiation cross teams.

About

solace redux middleware wrapper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp