npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-lenses-streaming

v1.1.1

Published

Client library for Lenses WS adapter

Downloads

5

Readme

Connect to Kafka via Lenses

Redux middleware that facilitates connection to a kafka backend running Landoop's Lenses.(Tested with v3.7)

Table of contents

Install

npm i --save redux-lenses-streaming rxjs

The only peer dependency that the library has is rxjs.

Usage

First setup the redux store with the kafka middleware:

import { createLensesMiddleware } from 'redux-lenses-streaming';

function configureStore() {
  const lensesMiddleware = createLensesMiddleware();
  //Any other middleware you might use
  const logger = createLogger();
  const middleware = [logger, lensesMiddleware];

  const store = createStore(
    rootReducer,
    applyMiddleware(...middleware),
  );

  return store;
}

Or you can customise the middleware with custom options in which case it will attempt to connect:

import { createLensesMiddleware } from 'redux-lenses-streaming';

function configureStore() {
  const lensesOptions = {
    host: 'cloudera02.landoop.com:24006/api/kafka/ws',
    clientId: 'MyClientsName',
    // See Options section for full list
  };

  const lensesMiddleware = createLensesMiddleware(lensesOptions);
  const middleware = [..., lensesMiddleware];

  const store = createStore(
    rootReducer,
    applyMiddleware(...middleware),
  );

  return store;
}

After, add the reducer:

import { combineReducers } from 'redux';
import { lensesReducer } from 'redux-lenses-streaming';
import sessionReducer from './sessionReducer';

const rootReducer = combineReducers({
  lenses: lensesReducer,
  //Add other application reducers where you listen
  // to the exposed actions (see list below)
  session: sessionReducer,
});

export default rootReducer;

Now you are ready to dispatch Actions using the provided action creators, that the middleware will intercept:

import { Actions } from 'redux-lenses-streaming';

dispatch(Actions.connect(options));
dispatch(Actions.login(options));
dispatch(Actions.publish(payload));
dispatch(Actions.subscribe(payload));
dispatch(Actions.unsubscribe(payload));
dispatch(Actions.disconnect());
...

You can also listen to various Action Types, dispatched by the middleware:

import { Type } from 'redux-lenses-streaming';

export const Type = {
  KAFKA_MESSAGE
  KAFKA_HEARTBEAT
  CONNECT
  CONNECT_SUCCESS
  CONNECT_FAILURE
  DISCONNECT
  DISCONNECT_SUCCESS
  DISCONNECT_FAILURE
  LOGIN
  LOGIN_SUCCESS
  LOGIN_FAILURE
  PUBLISH
  PUBLISH_SUCCESS
  PUBLISH_FAILURE
  SUBSCRIBE
  SUBSCRIBE_SUCCESS
  SUBSCRIBE_FAILURE
  UNSUBSCRIBE
  UNSUBSCRIBE_SUCCESS
  UNSUBSCRIBE_FAILURE
};
...

Options

Passed when creating middleware or when dispatching connect action.

const defaultOptions = {
  host: '',
  clientId: '',
  user: '',
  password: '',
  secure: false,
  timeout: 5000,
  autoCommitDelay: -1,
};

// For login action creator:
const options = {
  user: '',
  password: '',
};

host (String)

Web socket address, including port. If wss:// is not set, it will be added by the library. Example of address: test.landoop.com:21112/api/kafka/ws wss://test.landoop.com:21112/api/kafka/ws

Default:

clientId (String)

Client Id. If previous session found, it will send back messages on topic subscription.

Default:

user (String)

User for authentication.

Default:

password (String)

Password for authentication.

Default:

timeout (Integer)

Timeout (ms) before publish / subscribe fail.

Default: 5000

autoCommitDelay (Integer)

Delay (ms) for autocommiting last message. If -1, then you will need to manually send commit message.

Default: -1

secure (Boolean)

Force connection to wss.

Default: false

To Do

  • [ ] Add Angular implementation
  • [ ] Support message batching
  • [ ] Handle unexpected disconnects and reconnection attempt
  • [ ] Add delay options
  • [ ] Tests

Notes

  • Tested with Redux v3.7

License

All copyrights reserved - Landoop LTD 2016-2018