examples

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2017 License: Apache-2.0 Imports: 0 Imported by: 0

README

CN-infra examples

The examples folder contains several executable examples (built from their respective main.go files) used to illustrate the cn-infra functionality. While most of the examples show a very simple use case, they still need to connect to ETCD and/or Kafka. Therefore, you need to have running instances of Etcd and Kafka to which the examples can connect.

Examples with the suffix _lib demonstrate the usage of CN-Infra APIs in generic Go programs. You can simply import the CN-Infra library where the API is declared into your program and starting using the API.

Examples with the suffix _plugin demonstrate the usage of CN-Infra APIs within the context of plugins. Plugins are the basic building blocks of any given CN-Infra application. The CNB-Infra plugin framework provides plugin initialization and graceful shutdown and supports uniform dependency injection mechanism to manage dependencies between plugins.

Current examples:

  • cassandra lib shows how to use the Cassandra data broker API to access the Cassandra database,
  • datasync plugin showcases the data synchronization APIs of the datasync package on an example plugin,
  • etcdv3 lib shows how to use the ETCD data broker API to write data into ETCD and catch this change as an event by the watcher,
  • flags plugin registers flags and shows their runtime values in an example plugin,
  • kafka lib shows how to use the Kafka messaging library on set of individual tools (producer, sync and async consumer),
  • kafka plugin (non-clustered) contains a simple plugin which registers a Kafka consumer and sends a test notification,
  • kafka plugin (clustered) contains a simple plugin which registers a Kafka consumer watching on specific partition/offset and sends a test notification to partition in Kafka cluster
  • logs lib shows how to use the logger library and switch between the log levels,
  • logs plugin showcases how to ue the logger library in a simple plugin,
  • redis lib contains several examples that use the Redis data broker API,
  • model show how to define a custom data model using Protocol Buffers and how to integrate it into the application,
  • simple-agent showcases an approach how a set of plugins can be turned into an application.

How to run an example

1. Start ETCD server on localhost

sudo docker run -p 2379:2379 --name etcd --rm \
quay.io/coreos/etcd:v3.0.16 /usr/local/bin/etcd \
-advertise-client-urls http://0.0.0.0:2379 \
-listen-client-urls http://0.0.0.0:2379

2. Start Kafka

sudo docker run -p 2181:2181 -p 9092:9092 --name kafka --rm \
 --env ADVERTISED_HOST=172.17.0.1 --env ADVERTISED_PORT=9092 spotify/kafka

3. Start the desired example

Each example can be started now from its directory.

go run main.go  \
--etcdv3-config=/opt/vnf-agent/dev/etcd.conf \
--kafka-config=/opt/vnf-agent/dev/kafka.conf

Documentation

Overview

Package examples contains examples that demonstrate the usage of various cn-infra components.

Directories

Path Synopsis
etcdv3_lib
model/phonebook
Package phonebook is a generated protocol buffer package.
Package phonebook is a generated protocol buffer package.
view
Package view contains an example that shows how to read data from etcdv3.
Package view contains an example that shows how to read data from etcdv3.
kafka_lib
mux
kafka_plugin
logs_lib
Package etcd_example is a generated protocol buffer package.
Package etcd_example is a generated protocol buffer package.
redis_lib
airport/model
Package flight is a generated protocol buffer package.
Package flight is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL