是否有某种方法可以获取部署的mule应用程序的基本mule应用程序名称?
到目前为止,我发现的唯一两个选项是:
muleContext.getConfiguration().getId() //which gives me some not so humanly-readable id of some sort.
和
muleEvent.getFlowConstruct().getName() //gives me that flow name from where this was called.
每个应用程序在部署时都在自己的应用程序目录中,是否无法从muleContext中获取此类或其他类似的可分辨名称?
亲切的问候
答案 0 :(得分:4)
检索应用程序名称的最简单方法是使用${app.name}
弹簧占位符将其注入组件
答案 1 :(得分:3)
这对我有用:
String appName = ((org.mule.module.launcher.MuleApplicationClassLoader)this.getClass().getClassLoader()).getAppName();
答案 2 :(得分:1)
对于 Mule 4.x ,有预定义的变量,其中之一是app.name
,用于在运行时检索应用程序名称。这是Mulesoft文档的链接,用于检查所有预定义的变量:
https://docs.mulesoft.com/mule-runtime/4.2/dataweave-variables-context
答案 3 :(得分:0)
对于MuleSoft 4.2.0,您可以使用静态Java函数加载应用程序名称:
ClassLoader cl = Class.forName("full-name-holding-this").getClassLoader();
Method getArtifactDescriptor = cl.getClass().getMethod("getArtifactDescriptor");
Object artifactDescriptor = getArtifactDescriptor.invoke(cl);
Method getName = artifactDescriptor.getClass().getMethod("getName");
Object appName = getName.invoke(artifactDescriptor);
return appName.toString();