Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support asyncapi http proxy using asyncapi.yaml #799

Merged
merged 40 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
65aad28
skeleton
bmaidics Jan 25, 2024
33be2a0
checkpoint
bmaidics Jan 26, 2024
a71c350
checkpoint
bmaidics Jan 30, 2024
db6997f
checkpoint
bmaidics Jan 30, 2024
0574abe
checkpoint
bmaidics Feb 3, 2024
63136cd
checkpoint
bmaidics Feb 5, 2024
0833f4d
checkpoint
bmaidics Feb 6, 2024
ae38add
Checkpoint
bmaidics Feb 7, 2024
e8f93fc
check
bmaidics Feb 8, 2024
4984c85
Checkpoint
bmaidics Feb 8, 2024
046583b
some fixes
bmaidics Feb 8, 2024
ffd9900
Merge remote-tracking branch 'upstream/develop' into asyncapi_mqtt
bmaidics Feb 9, 2024
a366947
checkpoint
bmaidics Feb 12, 2024
54aea97
Address review items
bmaidics Feb 12, 2024
51f039c
Merge remote-tracking branch 'upstream/develop' into asyncapi_mqtt
bmaidics Feb 12, 2024
ee96b7d
remove files
bmaidics Feb 12, 2024
504af3e
Reviews
bmaidics Feb 13, 2024
3ca1ffb
Add dependency to docker
bmaidics Feb 13, 2024
084c7ff
Fix
bmaidics Feb 13, 2024
24a2897
Fixes
bmaidics Feb 14, 2024
f7b2b50
Fix pom
bmaidics Feb 15, 2024
d13162d
Add asyncapi schema validation
bmaidics Feb 16, 2024
87d8ae6
Merge remote-tracking branch 'upstream/develop' into asyncapi_mqtt
bmaidics Feb 16, 2024
e484222
first commit
bmaidics Feb 13, 2024
607ea1a
checkpoint
bmaidics Feb 14, 2024
cc72a7a
REVERT BEFORE MERGE: Akram's HTTP changes
bmaidics Feb 14, 2024
6f3b371
checkpoint
bmaidics Feb 14, 2024
3f9c72f
REVERT THIS AS WELL
bmaidics Feb 14, 2024
3ad70d6
checkpoint
bmaidics Feb 15, 2024
8a8aae2
Fix tests
bmaidics Feb 15, 2024
12f7619
Test http
bmaidics Feb 15, 2024
049e595
Review items
bmaidics Feb 20, 2024
3267a92
Merge branch 'asyncapi_mqtt' into http_asyncapi
bmaidics Feb 20, 2024
0a2fb4e
Merge fixes
bmaidics Feb 20, 2024
7d05a57
Merge remote-tracking branch 'upstream/develop' into asyncapi_mqtt
bmaidics Feb 21, 2024
4d59803
Use binding.qvault
bmaidics Feb 21, 2024
dd71f47
Merge branch 'asyncapi_mqtt' into http_asyncapi
bmaidics Feb 21, 2024
18acd92
Review fixes
bmaidics Feb 21, 2024
d99bb51
Merge remote-tracking branch 'upstream/develop' into http_asyncapi
bmaidics Feb 22, 2024
92b6ec2
Final feedback
bmaidics Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ bindings:
sni:
- http.example.net
alpn:
- http
- h2
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,41 @@

asyncapi: 3.0.0
info:
title: HTTP Zilla Proxy
version: 1.0.0
title: Swagger Petstore
license:
name: Aklivity Community License
name: MIT
version: 1.0.0
servers:
plain:
host: http://localhost:8080
protocol: http
protocolVersion: '1.1'
protocolVersion: '2.0'
defaultContentType: application/json

channels:
items:
address: /items
itemsbyid:
address: /items/{id}
pets:
address: /pets
showPetById:
address: /pets/{id}

operations:
postEvents:
createPets:
action: send
bindings:
http:
type: request
method: POST
channel:
$ref: '#/channels/items'
getEvents:
$ref: '#/channels/pets'
listPets:
action: receive
bindings:
http:
type: request
method: GET
channel:
$ref: '#/channels/pets'
getPets:
action: receive
bindings:
http:
Expand All @@ -54,9 +62,9 @@ operations:
limit:
type: number
channel:
$ref: '#/channels/itemsbyid'
$ref: '#/channels/showPetById'

components:
correlationIds:
itemsCorrelationId:
petsCorrelationId:
location: '$message.header#/idempotency-key'
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ bindings:
sni:
- http.example.net
alpn:
- http
- h2
exit: asyncapi0
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ connect "zilla://streams/asyncapi0"

write zilla:begin.ext ${asyncapi:beginEx()
.typeId(zilla:id("asyncapi"))
.operationId("postEvents")
.operationId("createPets")
.extension(http:beginEx()
.typeId(zilla:id("http"))
.header(":method", "POST")
.header(":scheme", "http")
.header(":path", "/items")
.header(":path", "/pets")
.header(":authority", "localhost:8080")
.header("content-type", "application/json")
.header("content-length", "8")
Expand All @@ -38,7 +38,7 @@ write close

read zilla:begin.ext ${asyncapi:matchBeginEx()
.typeId(zilla:id("asyncapi"))
.operationId("postEvents")
.operationId("createPets")
.extension(http:beginEx()
.typeId(zilla:id("http"))
.header(":status", "200")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ accepted

read zilla:begin.ext ${asyncapi:matchBeginEx()
.typeId(zilla:id("asyncapi"))
.operationId("postEvents")
.operationId("createPets")
.extension(http:beginEx()
.typeId(zilla:id("http"))
.header(":method", "POST")
.header(":scheme", "http")
.header(":path", "/items")
.header(":path", "/pets")
.header(":authority", "localhost:8080")
.header("content-type", "application/json")
.header("content-length", "8")
Expand All @@ -40,7 +40,7 @@ read closed

write zilla:begin.ext ${asyncapi:beginEx()
.typeId(zilla:id("asyncapi"))
.operationId("postEvents")
.operationId("createPets")
.extension(http:beginEx()
.typeId(zilla:id("http"))
.header(":status", "200")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# Copyright 2021-2023 Aklivity Inc.
#
# Aklivity licenses this file to you under the Apache License,
# version 2.0 (the "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#

connect "zilla://streams/asyncapi0"
option zilla:window 8192
option zilla:transmission "duplex"

write zilla:begin.ext ${asyncapi:beginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.session()
.clientId("client")
.build()
.build())
.build()}

read zilla:begin.ext ${asyncapi:matchBeginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.session()
.clientId("client")
.build()
.build())
.build()}

connected

read zilla:data.empty


connect "zilla://streams/asyncapi0"
option zilla:window 8192
option zilla:transmission "duplex"

write zilla:begin.ext ${asyncapi:beginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.publish()
.clientId("client")
.topic("sensor/one")
.build()
.build())
.build()}

connected

write zilla:data.ext ${mqtt:dataEx()
.typeId(zilla:id("mqtt"))
.publish()
.qos("AT_MOST_ONCE")
.expiryInterval(15)
.contentType("asyncapiMessage")
.format("TEXT")
.responseTopic("sensor/one")
.correlation("info")
.build()
.build()}
write "asyncapiMessage"
write flush


connect "zilla://streams/asyncapi0"
option zilla:window 8192
option zilla:transmission "duplex"

write zilla:begin.ext ${asyncapi:beginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.subscribe()
.clientId("client")
.filter("sensor/two", 1, "AT_MOST_ONCE", "SEND_RETAINED")
.build()
.build())
.build()}
connected
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#
# Copyright 2021-2023 Aklivity Inc.
#
# Aklivity licenses this file to you under the Apache License,
# version 2.0 (the "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#

accept "zilla://streams/asyncapi0"
option zilla:window 8192
option zilla:transmission "duplex"

accepted

read zilla:begin.ext ${asyncapi:matchBeginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.session()
.clientId("client")
.build()
.build())
.build()}

write zilla:begin.ext ${asyncapi:beginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.session()
.clientId("client")
.build()
.build())
.build()}

connected

write zilla:data.empty
write flush


accepted

read zilla:begin.ext ${asyncapi:matchBeginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.publish()
.clientId("client")
.topic("sensor/one")
.build()
.build())
.build()}

connected

read zilla:data.ext ${mqtt:dataEx()
.typeId(zilla:id("mqtt"))
.publish()
.qos("AT_MOST_ONCE")
.expiryInterval(15)
.contentType("asyncapiMessage")
.format("TEXT")
.responseTopic("sensor/one")
.correlation("info")
.build()
.build()}
read "asyncapiMessage"


accepted

read zilla:begin.ext ${asyncapi:matchBeginEx()
.typeId(zilla:id("asyncapi"))
.extension(mqtt:beginEx()
.typeId(zilla:id("mqtt"))
.subscribe()
.clientId("client")
.filter("sensor/two", 1, "AT_MOST_ONCE", "SEND_RETAINED")
.build()
.build())
.build()}

connected
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ write zilla:begin.ext ${http:beginEx()
.typeId(zilla:id("http"))
.header(":method", "POST")
.header(":scheme", "http")
.header(":path", "/items")
.header(":path", "/pets")
.header(":authority", "localhost:8080")
.header("content-type", "application/json")
.header("content-length", "8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ read zilla:begin.ext ${http:matchBeginEx()
.typeId(zilla:id("http"))
.header(":method", "POST")
.header(":scheme", "http")
.header(":path", "/items")
.header(":path", "/pets")
.header(":authority", "localhost:8080")
.header("content-type", "application/json")
.header("content-length", "8")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class AsyncapiIT

@Test
@Specification({
"${asyncapi}/publish.and.subscribe/client",
"${asyncapi}/publish.and.subscribe/server"
"${asyncapi}/mqtt/publish.and.subscribe/client",
"${asyncapi}/mqtt/publish.and.subscribe/server"
})
public void shouldPublishAndSubscribe() throws Exception
{
Expand All @@ -48,8 +48,8 @@ public void shouldPublishAndSubscribe() throws Exception

@Test
@Specification({
"${asyncapi}/create.item/client",
"${asyncapi}/create.item/server"
"${asyncapi}/http/create.pets/client",
"${asyncapi}/http/create.pets/server"
})
public void shouldCreateItem() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class HttpIT

@Test
@Specification({
"${http}/create.item/client",
"${http}/create.item/server"
"${http}/create.pets/client",
"${http}/create.pets/server"
})
public void shouldCreateItem() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.aklivity.zilla.runtime.binding.asyncapi.config.AsyncapiConfig;
import io.aklivity.zilla.runtime.binding.asyncapi.config.AsyncapiOptionsConfig;
import io.aklivity.zilla.runtime.binding.asyncapi.internal.view.AsyncapiServerView;
import io.aklivity.zilla.runtime.binding.asyncapi.internal.view.AsyncapiView;
import io.aklivity.zilla.runtime.engine.config.BindingConfig;
import io.aklivity.zilla.runtime.engine.config.CompositeBindingAdapterSpi;
import io.aklivity.zilla.runtime.engine.config.NamespaceConfigBuilder;
Expand All @@ -39,13 +40,14 @@ public BindingConfig adapt(
AsyncapiOptionsConfig options = (AsyncapiOptionsConfig) binding.options;
AsyncapiConfig asyncapiConfig = options.specs.get(0);
this.asyncApi = asyncapiConfig.asyncApi;
AsyncapiView asyncapiView = AsyncapiView.of(asyncApi);

//TODO: add composite for all servers
AsyncapiServerView firstServer = AsyncapiServerView.of(asyncApi.servers.entrySet().iterator().next().getValue());
this.qname = binding.qname;
this.qvault = String.format("%s:%s", binding.namespace, binding.vault);
this.qvault = binding.qvault;
this.protocol = resolveProtocol(firstServer.protocol(), options);
int[] compositeSecurePorts = resolvePortsForScheme(protocol.secureScheme);
int[] compositeSecurePorts = asyncapiView.resolvePortsForScheme(protocol.secureScheme);
this.isTlsEnabled = compositeSecurePorts != null;
return BindingConfig.builder(binding)
.composite()
Expand Down
Loading