# redux-solace

> solace redux middleware wrapper

Latest version **0.20.21** (published 2020-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-solace
pnpm add redux-solace
yarn add redux-solace
bun add redux-solace
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.20.21 |
| Published | 2020-08-14 |
| First published | 2019-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 93 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Wentao Li |
| Maintainers | albertli90 |
| Keywords | redux, solace, albert |

## Links

- npm: https://www.npmjs.com/package/redux-solace
- Repository: https://github.com/albertleigh/redux-solace
- Homepage: https://github.com/albertleigh/redux-solace#readme
- Issues: https://github.com/albertleigh/redux-solace/issues
- npm.io page: https://npm.io/package/redux-solace

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [redux](https://npm.io/package/redux.md) ^4.0.1
- [solclientjs](https://npm.io/package/solclientjs.md) =10.2.1
- [redux-actions](https://npm.io/package/redux-actions.md) ^2.6.4

## Recent versions

- 0.20.21 (latest) — 2020-08-14
- 0.20.21-next.0 (next) — 2020-08-13
- 0.20.20 — 2019-03-14
- 0.20.10 — 2019-03-13

## README

# Redux solace
[![version][version-badge]][CHANGELOG] [![license][license-badge]][LICENSE]

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](./DOCUMENTATION.md)

## Quick start

### Install

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

### Build the middleware and inject into store

User the `createSolaceMiddleware` to create one middleware and add it to middleware chain.

```javascript
    import  { createSolaceMiddleware } from 'redux-solace'
    
    const solaceMiddleware = createSolaceMiddleware();
    const middleware = compose(applyMiddleware(
        sagaMiddleware,
        solaceMiddleware
    ), devtools);
    
    const store = createStore(
        rootReducer,
        middleware
    )
    
```

Then inject the store into your frontend freawer like (React, Angular 5/6/7)
```jsx harmony
    const store = configureStore();
    
    store.dispatch(applicationStarted());
    
    ReactDom.render(
        <React.Fragment>
            <Provider store={store}>
                <App/>
            </Provider>
        </React.Fragment>
    );
```

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

```javascript
    // import the session package and rename it if needed
    import { Session as SolaceSession } from 'redux-solace';
    
    function* createOneSolaceSession(){
        const state = yield select(getSession);
        yield put (SolaceSession.actions.createAndConnectSession({
            hostUrl:            state.newSessionHostUrl,
            vpn:                state.newSessionVpn,
            username:           state.newSessionUsername,
            sessionCache:       state.newSessionCache,
            pass:               state.newSessionPass,
            config:{
                usePerMsgAck:   state.newSessionUsePerMsgAck,
            }
        }))
    }
    
    export default function*(){
        yield takeLatest(SESSION_SUBMIT_NEW, createOneSolaceSession);
    }
```

*sample  response action object*
```json
    {
      "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
```javascript
    import { Session as SolaceSession } from 'redux-solace';

    function* handleSolaceSessionResponse(action){
        // if there were any errors while creating the session, the action.error would be the error obj
        if (!action.error){
            yield put(applicationNewSnackbar({message:`${action.payload.result.name} created`}))
            
        }
    }
    
    export default function*(){
        yield takeLatest(SolaceSession.actions.CREATE_AND_CONNECT_SESSION_RES, handleSolaceSessionResponse);
    }
```

or a `SOLACE_CONTEXT_CHANGED` action will be also emitted if sessions changed

```javascript
    import { handleActions } from 'redux-actions';
    import { Session as SolaceSession } from 'redux-solace';
    
    const defaultState = {...};
    
    export default handleActions({
        [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.  


[LICENSE]: ./LICENSE.md
[CHANGELOG]: ./CHANGELOG.md

[version-badge]: https://img.shields.io/npm/v/redux-solace.svg
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg

---
_Source: https://npm.io/package/redux-solace · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
