Skip to content

Commit

Permalink
Feat: Add root config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Liel Almog authored and Liel Almog committed Jan 17, 2024
1 parent 2129766 commit 3eb1765
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Liel Almog

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0

version: "3"

services:
kafka:
image: docker.io/bitnami/kafka:3.6
ports:
- "29092:29092"
volumes:
- "kafka_data:/bitnami"
environment:
# KRaft settings
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093
# Listeners
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:29092
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092,EXTERNAL://localhost:29092
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=PLAINTEXT
hostname: kafka
networks:
- app-tier

kafka-ui:
image: docker.io/provectuslabs/kafka-ui:latest
ports:
- "8000:8080"
environment:
- DYNAMIC_CONFIG_ENABLED=true
networks:
- app-tier
volumes:
kafka_data:
driver: local
networks:
app-tier:
driver: bridge
35 changes: 35 additions & 0 deletions temp-uploader/configs/kafka.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Create a kafka producer without a topic

package configs

import (
"sync"

"github.com/segmentio/kafka-go"
)

var (
kafkaProducer *kafka.Writer
initKafkaProducerOnce sync.Once
)

const UploadFilesTopic = "upload-files"

type KafkaProducer struct {
Writer *kafka.Writer
}

func newKafkaProducer(brokers []string) *kafka.Writer {
return &kafka.Writer{
Addr: kafka.TCP(brokers...),
Balancer: &kafka.LeastBytes{},
}
}

func GetKafkaProducer() *kafka.Writer {
initKafkaProducerOnce.Do(func() {
kafkaProducer = newKafkaProducer([]string{"localhost:9092"})
})

return kafkaProducer
}

0 comments on commit 3eb1765

Please sign in to comment.