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

fix: support all RMQ exchanges in AsyncAPI #1679

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion faststream/asyncapi/schema/bindings/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ class Exchange(BaseModel):
vhost : virtual host of the exchange, default is "/"
"""

type: Literal[
"default",
"direct",
"topic",
"fanout",
"headers",
"x-delayed-message",
"x-consistent-hash",
"x-modulus-hash",
]

name: Optional[str] = None
type: Literal["default", "direct", "topic", "fanout", "headers"]
durable: Optional[bool] = None
autoDelete: Optional[bool] = None
vhost: str = "/"
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ types = [

lint = [
"faststream[types]",
"ruff==0.5.6",
"ruff==0.5.7",
"bandit==1.7.9",
"semgrep==1.84.0",
"semgrep==1.84.1",
"codespell==2.3.0",
]

Expand All @@ -130,8 +130,8 @@ testing = [
"fastapi==0.112.0",
"pydantic-settings>=2.0.0,<3.0.0",
"httpx==0.27.0",
"PyYAML==6.0.1",
"watchfiles==0.22.0",
"PyYAML==6.0.2",
"watchfiles==0.23.0",
"email-validator==2.2.0",
]

Expand Down
104 changes: 104 additions & 0 deletions tests/asyncapi/rabbit/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,107 @@ async def handle(msg): ...
"is": "routingKey",
}
}

def test_subscriber_headers_bindings(self):
broker = self.broker_class()

@broker.subscriber(
RabbitQueue("test", auto_delete=True),
RabbitExchange("test-ex", type=ExchangeType.HEADERS),
)
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"amqp": {
"bindingVersion": "0.2.0",
"exchange": {
"autoDelete": False,
"durable": False,
"name": "test-ex",
"type": "headers",
"vhost": "/",
},
"is": "routingKey",
}
}

def test_subscriber_xdelay_bindings(self):
broker = self.broker_class()

@broker.subscriber(
RabbitQueue("test", auto_delete=True),
RabbitExchange("test-ex", type=ExchangeType.X_DELAYED_MESSAGE),
)
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"amqp": {
"bindingVersion": "0.2.0",
"exchange": {
"autoDelete": False,
"durable": False,
"name": "test-ex",
"type": "x-delayed-message",
"vhost": "/",
},
"is": "routingKey",
}
}

def test_subscriber_consistent_hash_bindings(self):
broker = self.broker_class()

@broker.subscriber(
RabbitQueue("test", auto_delete=True),
RabbitExchange("test-ex", type=ExchangeType.X_CONSISTENT_HASH),
)
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"amqp": {
"bindingVersion": "0.2.0",
"exchange": {
"autoDelete": False,
"durable": False,
"name": "test-ex",
"type": "x-consistent-hash",
"vhost": "/",
},
"is": "routingKey",
}
}

def test_subscriber_modules_hash_bindings(self):
broker = self.broker_class()

@broker.subscriber(
RabbitQueue("test", auto_delete=True),
RabbitExchange("test-ex", type=ExchangeType.X_MODULUS_HASH),
)
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"amqp": {
"bindingVersion": "0.2.0",
"exchange": {
"autoDelete": False,
"durable": False,
"name": "test-ex",
"type": "x-modulus-hash",
"vhost": "/",
},
"is": "routingKey",
}
}
Loading