code: def kafka_service():
      TOPIC = "test-%i" % random.randint(0, 10000)
      if _kafka[0] is None:
          if LAUNCH_KAFKA:
              launch_kafka()
          else:
              raise pytest.skip.Exception(
                  "Kafka not available. "
                  "To launch kafka use `export STREAMZ_LAUNCH_KAFKA=true`"
              )
  
          producer = ck.Producer(
              {
                  "bootstrap.servers": "localhost:9092",
                  "topic.metadata.refresh.interval.ms": "5000",
              }
          )
          producer.produce("test-start-kafka", b"test")
          out = producer.flush(10)
          if out > 0:
              raise RuntimeError("Timeout waiting for kafka")
          _kafka[0] = producer
      yield _kafka[0], TOPIC
  
imports: import asyncio
  import atexit
  from contextlib import contextmanager
  from flaky import flaky
  import os
  import pytest
  import random
  import shlex
  import subprocess
  import time
  from tornado import gen
  from ..core import Stream
  from ..dask import DaskStream
  from streamz.utils_test import gen_test, wait_for, await_for
  from distributed.utils_test import gen_cluster
label_desc: Use image node_id 3 for calling a global function with example usage: kafka_service() without return types