Azure 应用服务中的 Quartz 设置失败
Quartz setup failure in Azure App Service
我已经启动了 Azure 应用程序服务 运行。 Spring 启动应用已部署。当我尝试在 Spring 启动应用程序中添加 Quartz 调度程序设置时,它在本地工作正常。但是当我们转移到 Azure 应用程序时,调度程序设置未启动并显示以下消息。
基本上就是找host name,在Azure App service中能不能找到host name?解析主机名需要任何配置吗?
2020-05-08 11:35:57.155 ERROR 123 --- [main] org.quartz.impl.StdSchedulerFactory : Couldn't generate instance Id!
org.quartz.SchedulerException: Couldn't get host name!at org.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:36)at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1247)at
请注意:
在 Quartz 中注释属性将设置默认值,但我们需要使用自动方法
org.quartz.scheduler.instanceId=自动
我不确定您是否可以获取应用程序服务的主机名,您的代码是 运行,但是您可以使用 spring.quartz.properties.org.quartz.scheduler.instanceIdGenerator.class=CustomInstanceIDGenerator.class
中概述的 this blog post,其中 CustomInstnaceIDGenerator 是
public class CustomInsntanceIdGenerator implements InstanceIdGenerator {
@Override
public String generateInstanceId() throws SchedulerException {
try {
return UUID.randomUUID().toString();
} catech (Exception ex) {
throw new SchedulerException("Couldn't genereate UUID", ex);
}
}
}
这将使您不依赖于主机名。
编辑:试一试
private String getComputerName()
{
Map<String, String> env = System.getenv();
if (env.containsKey("COMPUTERNAME"))
return env.get("COMPUTERNAME");
else if (env.containsKey("HOSTNAME"))
return env.get("HOSTNAME");
else
return "Unknown Computer";
}
当您使用 spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
应用程序 属性 时会发生这种情况。为了克服这个问题,你必须在你的主机文件中映射 127.0.0.1 <machine ip>
,否则它会抛出 java.net.UnknownHostException: ip-1x-xx-xx-2xx: Temporary failure in name resolution
或者如果你想从系统 属性 中提供一些独特的价值,你必须改变
spring.quartz.properties.org.quartz.scheduler.instanceId=SYS_PROP
根据文档。
org.quartz.scheduler.instanceId
Can be any string, but must be unique for all schedulers working as if
they are the same ‘logical’ Scheduler within a cluster. You may use
the value “AUTO” as the instanceId if you wish the Id to be generated
for you. Or the value “SYS_PROP” if you want the value to come from
the system property “org.quartz.scheduler.instanceId”.
我已经启动了 Azure 应用程序服务 运行。 Spring 启动应用已部署。当我尝试在 Spring 启动应用程序中添加 Quartz 调度程序设置时,它在本地工作正常。但是当我们转移到 Azure 应用程序时,调度程序设置未启动并显示以下消息。
基本上就是找host name,在Azure App service中能不能找到host name?解析主机名需要任何配置吗?
2020-05-08 11:35:57.155 ERROR 123 --- [main] org.quartz.impl.StdSchedulerFactory : Couldn't generate instance Id!
org.quartz.SchedulerException: Couldn't get host name!at org.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:36)at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1247)at
请注意: 在 Quartz 中注释属性将设置默认值,但我们需要使用自动方法 org.quartz.scheduler.instanceId=自动
我不确定您是否可以获取应用程序服务的主机名,您的代码是 运行,但是您可以使用 spring.quartz.properties.org.quartz.scheduler.instanceIdGenerator.class=CustomInstanceIDGenerator.class
中概述的 this blog post,其中 CustomInstnaceIDGenerator 是
public class CustomInsntanceIdGenerator implements InstanceIdGenerator {
@Override
public String generateInstanceId() throws SchedulerException {
try {
return UUID.randomUUID().toString();
} catech (Exception ex) {
throw new SchedulerException("Couldn't genereate UUID", ex);
}
}
}
这将使您不依赖于主机名。
编辑:试一试
private String getComputerName()
{
Map<String, String> env = System.getenv();
if (env.containsKey("COMPUTERNAME"))
return env.get("COMPUTERNAME");
else if (env.containsKey("HOSTNAME"))
return env.get("HOSTNAME");
else
return "Unknown Computer";
}
当您使用 spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
应用程序 属性 时会发生这种情况。为了克服这个问题,你必须在你的主机文件中映射 127.0.0.1 <machine ip>
,否则它会抛出 java.net.UnknownHostException: ip-1x-xx-xx-2xx: Temporary failure in name resolution
或者如果你想从系统 属性 中提供一些独特的价值,你必须改变
spring.quartz.properties.org.quartz.scheduler.instanceId=SYS_PROP
根据文档。
org.quartz.scheduler.instanceId
Can be any string, but must be unique for all schedulers working as if they are the same ‘logical’ Scheduler within a cluster. You may use the value “AUTO” as the instanceId if you wish the Id to be generated for you. Or the value “SYS_PROP” if you want the value to come from the system property “org.quartz.scheduler.instanceId”.