-
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.
- Loading branch information
1 parent
8957154
commit 7664592
Showing
10 changed files
with
143 additions
and
95 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
52 changes: 0 additions & 52 deletions
52
...jd/live/agent/plugin/transmission/rocketmq/v4/interceptor/MQClientAPIImplInterceptor.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
.../jd/live/agent/plugin/transmission/rocketmq/v4/interceptor/MQProducerSendInterceptor.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.plugin.transmission.rocketmq.v4.interceptor; | ||
|
||
import com.jd.live.agent.bootstrap.bytekit.context.ExecutableContext; | ||
import com.jd.live.agent.core.plugin.definition.InterceptorAdaptor; | ||
import com.jd.live.agent.governance.context.RequestContext; | ||
import org.apache.rocketmq.common.message.Message; | ||
|
||
import java.util.Collection; | ||
|
||
public class MQProducerSendInterceptor extends InterceptorAdaptor { | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public void onEnter(ExecutableContext ctx) { | ||
Object argument = ctx.getArguments()[0]; | ||
if (argument instanceof Message) { | ||
attachTag((Message) argument); | ||
} else if (argument instanceof Collection) { | ||
attachTag((Collection<Message>) argument); | ||
} | ||
} | ||
|
||
private void attachTag(Collection<Message> messages) { | ||
RequestContext.cargos(cargo -> | ||
messages.forEach( | ||
message -> message.putUserProperty(cargo.getKey(), cargo.getValue()))); | ||
} | ||
|
||
private void attachTag(Message message) { | ||
RequestContext.cargos(cargo -> message.putUserProperty(cargo.getKey(), cargo.getValue())); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...com/jd/live/agent/plugin/transmission/rocketmq/v4/interceptor/MessageUtilInterceptor.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,52 @@ | ||
/* | ||
* 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.plugin.transmission.rocketmq.v4.interceptor; | ||
|
||
import com.jd.live.agent.bootstrap.bytekit.context.ExecutableContext; | ||
import com.jd.live.agent.bootstrap.bytekit.context.MethodContext; | ||
import com.jd.live.agent.core.plugin.definition.InterceptorAdaptor; | ||
import com.jd.live.agent.governance.context.bag.CargoRequire; | ||
import com.jd.live.agent.governance.context.bag.CargoRequires; | ||
import org.apache.rocketmq.common.message.Message; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MessageUtilInterceptor extends InterceptorAdaptor { | ||
|
||
private final CargoRequire require; | ||
|
||
public MessageUtilInterceptor(List<CargoRequire> requires) { | ||
this.require = new CargoRequires(requires); | ||
} | ||
|
||
@Override | ||
public void onSuccess(ExecutableContext ctx) { | ||
MethodContext mc = (MethodContext) ctx; | ||
attachTag((Message) mc.getArgument(0), (Message) mc.getResult()); | ||
} | ||
|
||
private void attachTag(Message request, Message response) { | ||
Map<String, String> properties = request.getProperties(); | ||
if (properties != null) { | ||
properties.forEach((k, v) -> { | ||
if (require.match(k)) { | ||
response.putUserProperty(k, v); | ||
} | ||
}); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ain/resources/META-INF/services/com.jd.live.agent.core.plugin.definition.PluginDefinition
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
com.jd.live.agent.plugin.transmission.rocketmq.v4.definition.MessageDefinition | ||
com.jd.live.agent.plugin.transmission.rocketmq.v4.definition.MQClientAPIImplDefinition | ||
com.jd.live.agent.plugin.transmission.rocketmq.v4.definition.MessageUtilDefinition | ||
com.jd.live.agent.plugin.transmission.rocketmq.v4.definition.MQProducerDefinition |
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