使用嵌入 Windows 服务的 Quartz.Net

发布于 2024-11-08 00:15:29 字数 1365 浏览 1 评论 0 原文

我正在尝试使用 Quartz.Net 来安排我开发的 Windows 服务中的作业。

我在 Onstart 方法中添加了以下代码,scheduler 是一个 Class 属性 私有只读 IScheduler 调度程序;

logger = LogManager.GetLogger(typeof (TelegestionService));
调度程序 = new StdSchedulerFactory().GetScheduler();
var job = new JobDetail("job1", "group1", typeof (HelloJob));
var 触发器 = new SimpleTrigger("trigger1", "group1", runTime);
Scheduler.ScheduleJob(作业,触发器);

这对我来说效果很好。我运行了作业。

现在我正在尝试使调度程序嵌入远程可访问,基于 Quartz 源示例中的Example12(控制台服务器/客户端工作正常)。

<代码> var 属性 = new NameValueCollection();
属性["quartz.scheduler.instanceName"] = "RemoteServer";
属性[“quartz.threadPool.type”] =“Quartz.Simpl.SimpleThreadPool,Quartz”;
属性[“quartz.threadPool.threadCount”] =“5”;
属性["quartz.threadPool.threadPriority"] = "正常";
属性[“quartz.scheduler.exporter.type”] =“Quartz.Simpl.RemotingSchedulerExporter,Quartz”;
属性[“quartz.scheduler.exporter.port”] =“555”;
属性["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
属性[“quartz.scheduler.exporter.channelType”] =“tcp”;

调度程序 = new StdSchedulerFactory(properties).GetScheduler();
服务正确启动,调度程序

也正确启动,但我无法使用控制台/Winform 客户端远程调度作业(连接被拒绝)。

我使用 SysInternals TcpView 检查了服务器上的侦听端口,但找不到上面指定的 555 端口。

我怀疑存在与 .Net Remoting 有关的问题,但不知道如何解决此问题。 有什么想法吗?

提前致谢。

I Am trying to use Quartz.Net so as to Schedule Jobs Within a Windows Service that I developped.

I included the following code on the Onstart Method, scheduler is a Class attribute
private readonly IScheduler scheduler;


logger = LogManager.GetLogger(typeof (TelegestionService));
scheduler = new StdSchedulerFactory().GetScheduler();
var job = new JobDetail("job1", "group1", typeof (HelloJob));
var trigger = new SimpleTrigger("trigger1", "group1", runTime);
scheduler.ScheduleJob(job, trigger);

This works fine for me. I got the Job running.

Now I'am trying to make the scheduler embedded remotely accessible, based en Example12 in the Quartz source Examples (the Console Server/Client works fine).


var properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "RemoteServer";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";

scheduler = new StdSchedulerFactory(properties).GetScheduler();

The service starts correctly and so does the scheduler but i cannot remotely schedule the Job using a Console/Winform Client (Connection refused).

I checked the LISTENING ports on my server using SysInternals TcpView and I cannot find the 555 port specified above.

Am suspecting an issue related to .Net Remoting but cannot figure out how to resolve this.
Any ideas ?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随心而道 2024-11-15 00:15:29

可以使用 http://topshelf-project.com/ 来托管 Scheduler,它将提供 hostFactory 并使用它可以通过 HttpSelfHostServer 托管主机,http 更好,因为您可以通过控制器调用作业。示例代码如下

希望有所帮助。

using System;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.SelfHost;
using Topshelf;
     class Program
    {
        static void Main(string[] args)
        {
            HostFactory.Run(hostConfigurator =>
            {
                if (!Uri.TryCreate("http://localhost:8080", UriKind.RelativeOrAbsolute, out var hostname))
                {
                    throw new ConfigurationErrorsException($"Could not uri");
                }

                var serviceName = "my service";

                var hostConfiguration = new HttpSelfHostConfiguration(hostname);
                hostConfiguration.Routes.MapHttpRoute("API", "{controller}/{action}/{id}", (object)new
                {
                    id = RouteParameter.Optional
                });

                var httpSelfHostServer = new HttpSelfHostServer(hostConfiguration);

                // Impl.Scheduler would be your implementation of scheduler
                hostConfigurator.Service<Impl.Scheduler>(s =>
                {
                    s.ConstructUsing(name => new Impl.Scheduler());
                    s.WhenStarted(tc =>
                    {
                        tc.Start();

                        httpSelfHostServer.OpenAsync().Wait();
                    });
                    s.WhenStopped(tc =>
                    {
                        tc.Stop();
                        //dispose scheduler implementation if using IOC container
                        httpSelfHostServer.CloseAsync().Wait();
                    });
                });
                hostConfigurator.RunAsLocalSystem();

                hostConfigurator.SetDescription(serviceName);
                hostConfigurator.SetDisplayName(serviceName);
                hostConfigurator.SetServiceName(serviceName);
            });
        }
    }

could use http://topshelf-project.com/ to host Scheduler which will provide hostFactory and using that could shelf host via HttpSelfHostServer, http is better as you could invoke job via controller. sample code as below

hope this helps.

using System;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.SelfHost;
using Topshelf;
     class Program
    {
        static void Main(string[] args)
        {
            HostFactory.Run(hostConfigurator =>
            {
                if (!Uri.TryCreate("http://localhost:8080", UriKind.RelativeOrAbsolute, out var hostname))
                {
                    throw new ConfigurationErrorsException($"Could not uri");
                }

                var serviceName = "my service";

                var hostConfiguration = new HttpSelfHostConfiguration(hostname);
                hostConfiguration.Routes.MapHttpRoute("API", "{controller}/{action}/{id}", (object)new
                {
                    id = RouteParameter.Optional
                });

                var httpSelfHostServer = new HttpSelfHostServer(hostConfiguration);

                // Impl.Scheduler would be your implementation of scheduler
                hostConfigurator.Service<Impl.Scheduler>(s =>
                {
                    s.ConstructUsing(name => new Impl.Scheduler());
                    s.WhenStarted(tc =>
                    {
                        tc.Start();

                        httpSelfHostServer.OpenAsync().Wait();
                    });
                    s.WhenStopped(tc =>
                    {
                        tc.Stop();
                        //dispose scheduler implementation if using IOC container
                        httpSelfHostServer.CloseAsync().Wait();
                    });
                });
                hostConfigurator.RunAsLocalSystem();

                hostConfigurator.SetDescription(serviceName);
                hostConfigurator.SetDisplayName(serviceName);
                hostConfigurator.SetServiceName(serviceName);
            });
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文