Skip to content

Commit

Permalink
add bases
Browse files Browse the repository at this point in the history
  • Loading branch information
lerenn committed Sep 8, 2023
1 parent 5f9929a commit d174e43
Show file tree
Hide file tree
Showing 43 changed files with 1,634 additions and 457 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

# Testing
tmp/
__debug_bin
33 changes: 21 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
.PHONY: brokers/up
brokers/up: ## Start the brokers
@docker-compose up -d

.PHONY: brokers/logs
brokers/logs: ## Get the brokers logs
@docker-compose logs

.PHONY: brokers/down
brokers/down: ## Stop the brokers
@docker-compose down

.PHONY: lint
lint: ## Lint the code
@LOG_LEVEL=error go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51 run

.PHONY: clean
clean: test/clean ## Clean up the project
clean: __examples/clean brokers/down ## Clean up the project

.PHONY: check
check: generate lint test ## Check that everything is ready for commit
check: generate lint examples test ## Check that everything is ready for commit

.PHONY: test/clean
test/clean:
.PHONY: __examples/clean
__examples/clean:
@$(MAKE) -C examples clean

.PHONY: test/integration
test/integration: ## Perform integration tests
.PHONY: examples
examples: brokers/up ## Perform examples
@$(MAKE) -C examples run

.PHONY: test/unit
test/unit: ## Perform unit tests
@go test ./... -coverprofile cover.out -v
.PHONY: test
test: brokers/up ## Perform tests
@go test ./... -coverprofile cover.out -v -timeout=30s
@go tool cover -func cover.out
@rm cover.out

.PHONY: test
test: test/unit test/integration ## Perform all tests

.PHONY: generate
generate: ## Generate files
@go generate ./...
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Generate Go client and server boilerplate from AsyncAPI specifications.
* AsyncAPI versions:
* 2.6.0
* Brokers:
* Kafka
* NATS
* Custom (implementation specified by the developer)
* *Open a ticket for any missing one that you would want to have here!*
Expand Down Expand Up @@ -173,7 +174,7 @@ import(
nc, _ := nats.Connect("nats://nats:4222")

// Create a new application controller
ctrl, _ := NewAppController(brokers.NewNATS(nc))
ctrl, _ := NewAppController(brokers.NewNATSController(nc))
defer ctrl.Close(context.Background())

// Subscribe to HelloWorld messages
Expand Down Expand Up @@ -225,7 +226,7 @@ import(
nc, _ := nats.Connect("nats://nats:4222")

// Create a new application controller
ctrl, _ := NewClientController(brokers.NewNATS(nc))
ctrl, _ := NewClientController(brokers.NewNATSController(nc))
defer ctrl.Close(context.Background())

// Send HelloWorld
Expand Down Expand Up @@ -296,7 +297,7 @@ func main() {
/* ... */

// Create a new server controller
ctrl, _ := NewAppController(brokers.NewNATS(nc))
ctrl, _ := NewAppController(brokers.NewNATSController(nc))
defer ctrl.Close(context.Background())

// Subscribe to all (we could also have just listened on the ping request channel)
Expand Down Expand Up @@ -366,7 +367,7 @@ import(
)

// Create a new app controller with a NATS controller for example
ctrl, _ := NewAppController(brokers.NewNATS(nc))
ctrl, _ := NewAppController(brokers.NewNATSController(nc))

// Add middleware
ctrl.AddMiddlewares(myMiddleware1, myMiddleware2 /*, ... */)
Expand Down Expand Up @@ -468,7 +469,7 @@ import(
)

// Create a new app controller with a NATS controller for example
ctrl, _ := NewAppController(brokers.NewNATS(nc))
ctrl, _ := NewAppController(brokers.NewNATSController(nc))

// Attach a logger (optional)
// You can find loggers in `github.com/lerenn/asyncapi-codegen/pkg/log` or create your own
Expand All @@ -490,7 +491,7 @@ import(
)

// Create a new app controller with a NATS controller for example
ctrl, _ := NewAppController(brokers.NewNATS(nc))
ctrl, _ := NewAppController(brokers.NewNATSController(nc))

// Add middleware
ctrl.AddMiddlewares(middleware.Logging(log.NewECS()))
Expand Down Expand Up @@ -542,7 +543,7 @@ import(
)

// Create a new app controller with a NATS controller for example
ctrl, _ := NewAppController(brokers.NewNATS(nc))
ctrl, _ := NewAppController(brokers.NewNATSController(nc))

// Set a logger
ctrl.SetLogger(SimpleLogger{})
Expand All @@ -565,7 +566,7 @@ import(
)

// Generate a new NATS controller
ctrl := brokers.NewNATS(nc)
ctrl := brokers.NewNATSController(nc)

// Set queue name on the NATS controller
ctrl.SetQueueName("my-custom-queue-name")
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.5'

services:
kafka:
image: 'bitnami/kafka:latest'
ports:
- 9092:9092
environment:
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_LISTENERS=INTERNAL://:9092,CONTROLLER://:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://:9092
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,INTERNAL:PLAINTEXT
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@:9093
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
networks:
- brokers
nats:
image: nats:alpine
ports:
- 4222:4222
networks:
- brokers

networks:
brokers:
1 change: 1 addition & 0 deletions examples/helloworld/nats/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ clean: ## Clean remains of run

.PHONY: run
run: ## Run the example
@$(MAKE) -C ../../.. brokers/up
@$(DOCKER_COMPOSE) run client
@$(DOCKER_COMPOSE) logs app

Expand Down
15 changes: 11 additions & 4 deletions examples/helloworld/nats/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/helloworld/nats/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
}

// Create a new application controller
ctrl, err := NewAppController(brokers.NewNATS(nc))
ctrl, err := NewAppController(brokers.NewNATSController(nc))
if err != nil {
panic(err)
}
Expand Down
14 changes: 11 additions & 3 deletions examples/helloworld/nats/client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/helloworld/nats/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
}

// Create a new client controller
ctrl, err := NewClientController(brokers.NewNATS(nc))
ctrl, err := NewClientController(brokers.NewNATSController(nc))
if err != nil {
panic(err)
}
Expand Down
17 changes: 5 additions & 12 deletions examples/helloworld/nats/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
version: "3.5"

services:
nats:
image: nats:alpine
# ports:
# - 4222:4222
networks:
- example-network
app:
depends_on:
- nats
image: golang:1.19.4
volumes:
- gocache:/go/pkg/mod
Expand All @@ -18,11 +10,10 @@ services:
working_dir: /go/asyncapi-codegen
command: go run ./examples/helloworld/nats/app
networks:
- example-network
- brokers
client:
depends_on:
- app
- nats
image: golang:1.19.4
volumes:
- gocache:/go/pkg/mod
Expand All @@ -31,11 +22,13 @@ services:
working_dir: /go/asyncapi-codegen
command: go run ./examples/helloworld/nats/client
networks:
- example-network
- brokers

volumes:
gocache:
gobuild:

networks:
example-network:
brokers:
name: asyncapi-codegen_brokers
external: true
1 change: 1 addition & 0 deletions examples/ping/kafka/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ clean: ## Clean remains of run

.PHONY: run
run: ## Run the example
@$(MAKE) -C ../../.. brokers/up
@$(DOCKER_COMPOSE) run client
@$(DOCKER_COMPOSE) logs server

Expand Down
19 changes: 15 additions & 4 deletions examples/ping/kafka/client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d174e43

Please sign in to comment.