How can I inject an event with tags over the EventService API

Hi,

I am looking for a solution to publish an event into the event-stream with Tags over http-post. In your DOCS you describe how to publish an event, but only regarding Pondv1, without for example Tags. I need to know how to do it after the schema of Pondv2. The most important aspect is the implementation of tags. How can I achieve something like this over http-post?

pond.emit(Tag(),Object)

Thank you for taking your time!

Hi @LennartBusekrus, have you seen https://developer.actyx.com/docs/os/api/event-service#publish-events? Does this help?

Or are you looking specifically for how Tags are represented in the payload?

Hi @wwerner thank you for your answer. Unfortunately your second assumption is most fitting. I need to find a way to publish events with Tags oder the EventService API, so yes I would need to know how to represent Tags in the payload

Unfortunately, setting Tags via the event service http API is currently not possible. The only way to set Tags is via the Pond. Is it possible for you to use the Pond?

Currently, tags are are set via web sockets and not included in the payload.

Hm that is sad to hear. Unfortunately no, I need to emit events from inside golang-code, so the only solution would be over http. Maybe I will send them to a docker-application, which will emit them to the pond, as a work-around

Nevertheless thank you for clarifying!

1 Like

This is something that might change in the next version, though I can’t say for sure as of now. But if it does, I’ll make sure to let you know!

1 Like

try this very simple app, that translates an HTTP request into a pond.emit().

Checkout this example:

import { Pond, SplashState, ConnectivityStatus, Tags } from '@actyx/pond'
import * as bodyParser from 'body-parser'
import * as cors from 'cors'
import * as express from 'express'

export type Params = { tags: string; payload: string }
export type Emit = { eventType: string }

const bodyLimit = '20mb'

Pond.default().then((pond) => {
  console.info('creating Pond - Api - Server')

  let swarmSyncState: SplashState | undefined = undefined
  let syncDone = false
  let nodeConnectivityState: ConnectivityStatus | undefined = undefined
  pond.waitForSwarmSync({
    enabled: true,
    onProgress: (s) => (swarmSyncState = s),
    onSyncComplete: () => (syncDone = true),
  })
  pond.getNodeConnectivity({ callback: (state) => (nodeConnectivityState = state) })

  const app = express()
  app.use(bodyParser.urlencoded({ extended: false, limit: bodyLimit }))
  app.use(bodyParser.json({ limit: bodyLimit }))
  app.use(cors())
  app.get('/', (_req, res) => res.send(pond.info()))
  app.get('/system/pondState', (_req, res) => {
    pond.getPondState((state) => {
      res.status(200).send(state)
    })
  })
  app.get('/system/sync', (_req, res) => {
    res.status(200).send({
      swarmSyncState,
      syncDone,
    })
  })
  app.get('/system/connectivity', (_req, res) => {
    res.status(200).send(nodeConnectivityState)
  })

  // there are no type definitions for express-ws
  app.post('/emit', async (req, res) => {
    console.log(req.body)
    const { tags, payload } = req.body

    if (!Array.isArray(tags) || tags.length === 0) {
      res.status(403)
      res.send({ message: `tags are invalid ${tags}` })
      return
    }
    //echo '{"tags": ["a", "b", "c"], "payload": "a"}' | curl -X "POST" -d @- -H "Content-Type: application/json"  localhost:4242/emit
    if (payload === undefined) {
      res.status(403)
      res.send({ message: `payload is missing` })
      return
    }
    const axTag = Tags(...tags)

    try {
      await pond.emit(axTag, payload).toPromise()
      res.sendStatus(204)
    } catch (e) {
      res.status(500)
      res.send(e)
    }
  })
  app.listen(4242)
})

dependencies:

    "@actyx/pond": "^1.1.0",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "express": "^4.17.1",

Please let me know if this helps.

1 Like

Thanks a lot!

Hi, @LennartBusekrus

Finally, https://www.npmjs.com/package/@actyx-contrib/actyx-http-connector arrived.
Check it out and let us know what you think.

1 Like

Thank you so much, exactly what I needed :slight_smile: !