Skip to content

Commit

Permalink
chore(examples): update docker compose files (reugn#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored May 14, 2024
1 parent 68478ed commit 096ebca
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
42 changes: 30 additions & 12 deletions examples/kafka/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
version: '3'

# docker exec --interactive --tty kafka-kafka-1 /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
# docker exec --interactive --tty kafka-kafka-1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test2 --from-beginning
# docker exec --interactive --tty broker /bin/kafka-console-producer --bootstrap-server localhost:9092 --topic test
# docker exec --interactive --tty broker /bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic test2 --from-beginning

# https://github.com/confluentinc/cp-all-in-one/blob/7.6.1-post/cp-all-in-one-community/docker-compose.yml
# https://docs.confluent.io/platform/current/installation/versions-interoperability.html
services:
zookeeper:
image: wurstmeister/zookeeper
image: confluentinc/cp-zookeeper:7.6.1
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka:2.13-2.8.1
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

broker:
image: confluentinc/cp-kafka:7.6.1
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "29092:29092"
- "9092:9092"
- "9101:9101"
environment:
KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
KAFKA_CREATE_TOPICS: "test:3:1,test2:3:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_JMX_PORT: 9101
KAFKA_JMX_HOSTNAME: localhost
AUTO_CREATE_TOPICS: true
6 changes: 4 additions & 2 deletions examples/kafka/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

hosts := []string{"127.0.0.1:9092"}
ctx := context.Background()
config := sarama.NewConfig()
config.Consumer.Group.Rebalance.Strategy = sarama.NewBalanceStrategyRoundRobin()
config.Consumer.Offsets.Initial = sarama.OffsetNewest
config.Producer.Return.Successes = true
config.Version, _ = sarama.ParseKafkaVersion("2.8.1")
config.Version, _ = sarama.ParseKafkaVersion("3.6.2")
groupID := "testConsumer"

source, err := ext.NewKafkaSource(ctx, hosts, groupID, config, "test")
Expand Down
22 changes: 17 additions & 5 deletions examples/pulsar/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
version: '3'
# docker exec --interactive --tty pulsar-standalone /pulsar/bin/pulsar-client produce test1 -m "test" -n 10
# docker exec --interactive --tty pulsar-standalone /pulsar/bin/pulsar-client consume -s sub test2 -n 0

services:
standalone:
image: apachepulsar/pulsar
image: apachepulsar/pulsar:3.2.2
container_name: pulsar-standalone
ports:
- "6650:6650"
expose:
- 8080
- 6650
environment:
- PULSAR_MEM=" -Xms512m -Xmx512m -XX:MaxDirectMemorySize=1g"
- BOOKIE_MEM=" -Xms512m -Xmx512m -XX:MaxDirectMemorySize=1g"
command: >
/bin/bash -c
"bin/apply-config-from-env.py conf/standalone.conf
&& bin/pulsar standalone"
networks:
- pulsar-network

dashboard:
image: apachepulsar/pulsar-dashboard
image: apachepulsar/pulsar-dashboard:2.8.1
container_name: pulsar-dashboard
depends_on:
- standalone
ports:
- "80:80"
environment:
- SERVICE_URL=http://standalone:8080
- SERVICE_URL=http://standalone:8080
networks:
- pulsar-network

networks:
pulsar-network:
driver: bridge
2 changes: 0 additions & 2 deletions examples/redis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
redis:
image: redis
Expand Down
2 changes: 1 addition & 1 deletion examples/redis/pubsub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
ext "github.com/reugn/go-streams/redis"
)

// docker exec -it pubsub bash
// https://redis.io/topics/pubsub
func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
Expand Down Expand Up @@ -39,5 +38,6 @@ func main() {
}

var toUpper = func(msg *redis.Message) string {
log.Printf("Got: %s", msg)
return strings.ToUpper(msg.Payload)
}
4 changes: 2 additions & 2 deletions examples/redis/stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// XREAD COUNT 1 BLOCK 100 STREAMS stream2 0
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
cancel()
defer cancel()

config := &redis.Options{
Addr: "localhost:6379", // use default Addr
Expand Down Expand Up @@ -52,7 +52,7 @@ func main() {
}

var toUpper = func(msg *redis.XMessage) *redis.XMessage {
fmt.Printf("Got: %v\n", msg.Values)
log.Printf("Got: %v", msg.Values)
values := make(map[string]any, len(msg.Values))
for key, element := range msg.Values {
values[key] = strings.ToUpper(fmt.Sprintf("%v", element))
Expand Down

0 comments on commit 096ebca

Please sign in to comment.