Nexus 2 - 插件开发 - 事件
Nexus 2 - plugin development - events
编辑:我想我发现我必须使用 EventBus。因此,我必须将我的监听器 class(带有@subscribe 方法的监听器)注册到 EventBus。我如何获取 Nexus 的 EventBus 实例来注册我的 "listener"?
我目前正在为 Nexus 2 开发一个 webhook 插件,更具体地说是 OSS 2.13.0-01。类似于 this (for Nexus 1.x). The eventinspector though does not work like that in Nexus 2.x. I browsed the source code of Nexus 2.x here,但我还没有得到线索。我最初的想法是,我只需要实现一个监听器,仅此而已,但我无法获得任何事件,也看不到任何好的调试机会来找出方法。所以:我如何监听事件以在 nexus 2.x 中发生该事件时调用我的方法?事件总线是正确的选择吗?
谢谢!
大崩溃
我不确定您对什么事件感兴趣,但我构建了一个插件来检测是否有新工件添加到 Nexus。我实施了 class
@Named
@Singleton
public class ArtifactFinder extends ComponentSupport implements EventSubscriber
并实现了一个方法
@Subscribe
public void onDeployEvent(RepositoryItemEventStoreCreate event)
{
StorageItem item = event.getItem();
writeOut(item, "+ ");
}
根据 JF Meiers 的回答,这里是 Nexus Repository Manager OSS 2.13.0-01 的工作版本,我们希望在其中获取所有 ItemEventStoreCreate 事件以在存储项目时发送 webhook:
@Named
@Singleton
public class testEventPlugin extends ComponentSupport implements EventSubscriber {
@Subscribe
public void onDeployEvent(RepositoryItemEventStoreCreate event) {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://api.webhookinbox.com/i/EfwQnwLM/in/");
try {
int statusCode = client.executeMethod(method);
byte[] responseBody = method.getResponseBody();
System.out.println(new String(responseBody));
} catch (Exception e) {
System.err.println("Fatal error: " + e.getMessage());
e.printStackTrace();
} finally {
method.releaseConnection();
}
}
}
谢谢!
大崩溃
编辑:我想我发现我必须使用 EventBus。因此,我必须将我的监听器 class(带有@subscribe 方法的监听器)注册到 EventBus。我如何获取 Nexus 的 EventBus 实例来注册我的 "listener"?
我目前正在为 Nexus 2 开发一个 webhook 插件,更具体地说是 OSS 2.13.0-01。类似于 this (for Nexus 1.x). The eventinspector though does not work like that in Nexus 2.x. I browsed the source code of Nexus 2.x here,但我还没有得到线索。我最初的想法是,我只需要实现一个监听器,仅此而已,但我无法获得任何事件,也看不到任何好的调试机会来找出方法。所以:我如何监听事件以在 nexus 2.x 中发生该事件时调用我的方法?事件总线是正确的选择吗?
谢谢! 大崩溃
我不确定您对什么事件感兴趣,但我构建了一个插件来检测是否有新工件添加到 Nexus。我实施了 class
@Named
@Singleton
public class ArtifactFinder extends ComponentSupport implements EventSubscriber
并实现了一个方法
@Subscribe
public void onDeployEvent(RepositoryItemEventStoreCreate event)
{
StorageItem item = event.getItem();
writeOut(item, "+ ");
}
根据 JF Meiers 的回答,这里是 Nexus Repository Manager OSS 2.13.0-01 的工作版本,我们希望在其中获取所有 ItemEventStoreCreate 事件以在存储项目时发送 webhook:
@Named
@Singleton
public class testEventPlugin extends ComponentSupport implements EventSubscriber {
@Subscribe
public void onDeployEvent(RepositoryItemEventStoreCreate event) {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://api.webhookinbox.com/i/EfwQnwLM/in/");
try {
int statusCode = client.executeMethod(method);
byte[] responseBody = method.getResponseBody();
System.out.println(new String(responseBody));
} catch (Exception e) {
System.err.println("Fatal error: " + e.getMessage());
e.printStackTrace();
} finally {
method.releaseConnection();
}
}
}
谢谢! 大崩溃