-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Routing by port
- Loading branch information
Showing
6 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...rnance-api/src/main/java/com/jd/live/agent/governance/invoke/filter/route/PortFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright © ${year} ${owner} (${email}) | ||
* | ||
* Licensed 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. | ||
*/ | ||
package com.jd.live.agent.governance.invoke.filter.route; | ||
|
||
import com.jd.live.agent.core.extension.annotation.Extension; | ||
import com.jd.live.agent.governance.annotation.ConditionalOnFlowControlEnabled; | ||
import com.jd.live.agent.governance.invoke.OutboundInvocation; | ||
import com.jd.live.agent.governance.invoke.filter.RouteFilter; | ||
import com.jd.live.agent.governance.invoke.filter.RouteFilterChain; | ||
import com.jd.live.agent.governance.request.Portable; | ||
import com.jd.live.agent.governance.request.ServiceRequest.OutboundRequest; | ||
|
||
/** | ||
* A class that implements the {@link RouteFilter} interface. | ||
* It filters outbound requests based on the port number. | ||
* | ||
* @since 1.6.0 | ||
*/ | ||
@Extension(value = "PortFilter", order = RouteFilter.ORDER_PORT) | ||
@ConditionalOnFlowControlEnabled | ||
public class PortFilter implements RouteFilter { | ||
|
||
@Override | ||
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) { | ||
T request = invocation.getRequest(); | ||
if (request instanceof Portable) { | ||
Integer port = ((Portable) request).getPort(); | ||
if (port != null) { | ||
invocation.getRouteTarget().filter(e -> e.isPort(port)); | ||
} | ||
} | ||
chain.filter(invocation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...e/joylive-governance-api/src/main/java/com/jd/live/agent/governance/request/Portable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright © ${year} ${owner} (${email}) | ||
* | ||
* Licensed 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. | ||
*/ | ||
package com.jd.live.agent.governance.request; | ||
|
||
/** | ||
* An interface representing an object that has a port. | ||
* Implementing classes should provide a method to get the port number. | ||
*/ | ||
public interface Portable { | ||
|
||
/** | ||
* Returns the port number of the request. | ||
* | ||
* @return The port number. | ||
*/ | ||
Integer getPort(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters