How to use the cloudevents.CloudEvent function in cloudevents

To help you get started, we’ve selected a few cloudevents examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / kar / examples / unit-tests / server.js View on Github external
type: type,
      source: source,
      data: 1
    })
    await events.publish(topic, e1)

    // Create event 2:
    var e2 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 2
    })
    await events.publish(topic, e2)

    // Create event 3:
    var e3 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 3
    })
    await events.publish(topic, e3)

    return 'OK'
  }
github IBM / kar / examples / unit-tests / server.js View on Github external
async pubsub (topic) {
    const source = 'numServer'
    const type = 'number'
    await events.subscribe(this, 'accumulate', topic) // subscribe actor to topic

    // Create event 1:
    var e1 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 1
    })
    await events.publish(topic, e1)

    // Create event 2:
    var e2 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 2
    })
    await events.publish(topic, e2)

    // Create event 3:
    var e3 = new cloudevents.CloudEvent({
github IBM / kar / examples / unit-tests / server.js View on Github external
async pubsub (topic) {
    const source = 'numServer'
    const type = 'number'
    await events.subscribe(this, 'accumulate', topic) // subscribe actor to topic

    // Create event 1:
    var e1 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 1
    })
    await events.publish(topic, e1)

    // Create event 2:
    var e2 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 2
    })
    await events.publish(topic, e2)

    // Create event 3:
    var e3 = new cloudevents.CloudEvent({
      type: type,
      source: source,
      data: 3
    })
    await events.publish(topic, e3)

    return 'OK'
  }
github IBM / kar / examples / actors-events / client.js View on Github external
async function main () {
  while (true) {
    // construct event
    const event = new CloudEvent({
      type: 'test.event',
      source: 'test.source',
      data: Date.now()
    })

    // publish event
    console.log('publish:', await events.publish('test-topic', event))

    // sleep 1s
    await new Promise(resolve => setTimeout(resolve, 1000))
  }
}
github IBM / kar / examples / actors-ykt / ykt.js View on Github external
const status = { site: this.name, siteEmployees, time }
    status.bucketSizeInMS = bucketSizeInMS
    status.reminderDelays = this.reminderDelays
    status.workerUpdateLatency = this.workerUpdateLatency
    if (siteEmployees > 0) {
      for (const s in States) {
        status[States[s]] = 0
      }
      for (const worker in this.workers) {
        status[this.workers[worker]] += 1
      }
      console.log(status)
    }

    // Construct Cloud Event containing the status report.
    var reportEvent = new CloudEvent({
      type: 'site.report',
      source: 'javascript.client',
      data: status
    })

    if (verbose) console.log(`Publish event: ${reportEvent}`)

    // Publish report as an event.
    events.publish('siteReport', reportEvent)

    return status
  }
github IBM / kar / examples / camel-k / processor.js View on Github external
// Read previous value.
      var prevCounter = this.counter - 1
      var previousPrice = this.package[`stock_${prevCounter}`].price
      var increase = currentPrice - previousPrice
      if (increase >= 0) {
        var userInfo = `Price of ${stock.name} has increased by ${increase} to ${currentPrice}.`

        if (newHigh) {
          userInfo += ' Stock has reached a new high this session. Sell, sell, sell!'
        }

        // Create a CloudEvent to hold to result.
        // Note: data_base64 is not available in the cloud events javascript SDK as is available in the
        // Java SDK. We use the plain data field. The Java Cloud Event deserialization can handle
        // of this case.
        var slackStockEvent = new CloudEvent({
          type: 'stock.output',
          source: 'kar.processor',
          data: userInfo
        })

        // Publish event.
        events.publish('OutputStockEvent', slackStockEvent)
      }
    }

    // Increment the counter and return.
    this.counter += 1
    return this.counter
  }
}
github IBM / kar / examples / actors-ykt / ykt-aggregator.js View on Github external
// Compose message.
      var slackMessage = 'Employee count: '
      var onSiteEmployees = false
      for (var key in sites) {
        if (sites[key] > 0) {
          slackMessage += ` ${key}: ${sites[key]} `
          onSiteEmployees = true
        }
      }

      // If there are no employees left anywhere, print special message.
      if (!onSiteEmployees) {
        slackMessage = 'End of work day. No on-site employees.'
      }

      var slackReportEvent = new CloudEvent({
        type: 'employee.count',
        source: 'ykt.aggregator',
        data: slackMessage
      })

      // Publish event.
      events.publish('outputReport', slackReportEvent)
    }

    // Increment the counter and return.
    this.counter += 1
    return this.counter
  }
}

cloudevents

CloudEvents SDK for JavaScript

Apache-2.0
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis

Popular cloudevents functions