Skip to main content

IBM Streams Kafka integration

Project description

Overview

Provides functions to read messages from a Kafka broker as a stream and submit tuples to a Kafka broker as messages.

The broker configuration must be done with properties in an application configuration or by using a dictionary variable. The minimum set of properties must contain the bootstrap.servers configuration, which is valid for both consumers and producers, i.e. for the subscribe and publish functions.

It is also possible to use different application configurations for subscribe and publish when special consumer or producer configs must be used.

Sample

A simple hello world example of a Streams application publishing to a topic and the same application consuming the same topic:

from streamsx.topology.topology import Topology
from streamsx.topology.schema import CommonSchema
from streamsx.topology.context import submit, ContextTypes
import streamsx.kafka as kafka
import time

def delay(v):
    time.sleep(5.0)
    return True

topology = Topology('KafkaHelloWorld')

to_kafka = topology.source(['Hello', 'World!'])
to_kafka = to_kafka.as_string()
# delay tuple by tuple
to_kafka = to_kafka.filter(delay)

# Publish a stream to Kafka using TEST topic, the Kafka servers
# assuming, the broker is running on localhost, port 9092
kafka_props = {}
kafka_props['bootstrap.servers'] = 'localhost:9092'
kafka.publish(to_kafka, 'TEST', kafka_props)

# Subscribe to same topic as a stream
from_kafka = kafka.subscribe(topology, 'TEST', kafka_props, CommonSchema.String)

# You'll find the Hello World! in stdout log file:
from_kafka.print()

submit(ContextTypes.DISTRIBUTED, topology)
# The Streams job is kept running.

Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamsx.kafka-1.6.2.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamsx.kafka-1.6.2-py2.py3-none-any.whl (24.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file streamsx.kafka-1.6.2.tar.gz.

File metadata

  • Download URL: streamsx.kafka-1.6.2.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for streamsx.kafka-1.6.2.tar.gz
Algorithm Hash digest
SHA256 cacf506be183589891a9deb5504f2c82318b69055d22f51bc93a786a055db1c9
MD5 dc564799fb75bcfba1d64cca450377f2
BLAKE2b-256 9a3cf245d64b60924e002f2cb5e7215e83f6583dcf8fab12715838eca5b563ef

See more details on using hashes here.

File details

Details for the file streamsx.kafka-1.6.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for streamsx.kafka-1.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f16d736f33b2b3ff84155882635ce863a6547cea8cf76b5f9113f9e0e232f6dd
MD5 93c5897f22d7f26be28f0f3973353082
BLAKE2b-256 f0b9f3233a473395a2195dbb285fe6c28abc39a5c20aadbf9795a671a35b559f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page