9

I gave Node-Red a short test-run this week. It is not clear to me whether it supports flows that encompass more than one request. Does Node-Red have a request-per-flow or a session-per-flow model?

Having worked with data-flow based programming tools for Business Process Modeling (webMethods and Tibco), I see one of their key features is the ability to model sessions and workflows. These tools are, however, rather large for the purposes of most IoT projects so it would be great if something similar could be accomplished with Node-Red.

A follow-up question, in case Node-Red does not support this, is whether there are some simple tools that do support graphical modeling of session flows?

Aurora0001
  • 18,520
  • 13
  • 55
  • 169
Chris Steinbach
  • 734
  • 4
  • 13

2 Answers2

5

Short answer is yes, at least according this feature request:

Define convention for 'stateful' sessions #63

This request is closed with a commit stating that a web socket node is added, which is based on a session token.

Helmar
  • 8,450
  • 6
  • 36
  • 84
mico
  • 4,351
  • 1
  • 18
  • 27
3

The answer is no and yes.

Flows in node-red are pretty static, there is no notion of instantiating a flow when the first requests comes in such that you might have an instance of a flow per request.

There is also no built-in notion of a session that would allow you to associate messages flowing through flows with a session.

However, you can relatively easily construct these things yourself. Node-red provides a notion of flow and global state, which is accessed using the flow and global objects, see https://nodered.org/docs/writing-functions#storing-data. What you would do is send a cookie to clients and then explicitly associate an incoming request with saved global or flow state. You can then write code that is "session aware" based on the saved session state. This works well in function nodes, but you will hit some issues with the built-in nodes that do things like rate limit or split & merge messages because these are not generally aware of the session notion.

In the pizza example you would maintain the state of an order in the flow or global context and you would access the appropriate order's state based on the cookie value.

TvE
  • 211
  • 1
  • 4