简体   繁体   English

如何使用 Confluent-Kafka-Go 创建窗口服务

[英]How To Create a Window Service Using Confluent-Kafka-Go

I have a service when I use golang.org/x/sys/windows/svc to create my api as window service.当我使用 golang.org/x/sys/windows/svc 创建我的 api 作为窗口服务时,我有一个服务。 This works perfect.这工作完美。 I was able to follow this How to use Golang client on Windows #128 and thats work to.我能够按照如何在 Windows #128 上使用 Golang 客户端进行操作。 I can consume, produce my api work as I want.我可以根据需要消费、生产我的 api 工作。 I can use both librerys and when I run the service in debug mode everything is fine.我可以同时使用库,当我在调试模式下运行服务时,一切都很好。 But when the api is a window service the service dont start I got a 1053 error message.但是当 api 是窗口服务时,该服务无法启动,我收到了 1053 错误消息。 I was running several test and I can say the service dont work when I use the confluent librery.我正在运行几个测试,当我使用融合库时,我可以说该服务不起作用。 I know that because this librery dont support window something is missing when .exe run as service but I can figure out what it is.我知道因为这个库不支持窗口,所以当 .exe 作为服务运行时会丢失一些东西,但我可以弄清楚它是什么。

How to reproduce I make a little program apart from my main project.如何重现我在我的主要项目之外做了一个小程序。 Just copy and paste the example from here golang.org/x/sys/windows/svc and add a consumer from confluent.只需从 golang.org/x/sys/windows/svc 复制并粘贴示例,然后从 confluent 添加一个使用者。

    if _, err := os.Stat(".\LOGSmsPrueba\"); os.IsNotExist(err) {
    os.MkdirAll(".\LOGSmsPrueba\", 0700)
    }
    filelogs, _ := os.OpenFile(".\LOGSmsPrueba\LOGS.log", os.O_APPEND|os.O_CREATE|os.O_RDWR, 
    0644)
    
    defer filelogs.Close()
    
    log := zerolog.New(filelogs).With().Logger()
    log.Debug().Msg("Before The Thread Of Consumer")
    go func() {
    
        log := zerolog.New(filelogs).With().Logger()
    
        kafkaservice.ConsumidorKafka(&log)
    }()
    
    changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
    loop:
    for {
    select {
    
        case c := <-r:
            switch c.Cmd {
            case svc.Interrogate:
                changes <- c.CurrentStatus
            
                time.Sleep(100 * time.Millisecond)
                changes <- c.CurrentStatus
            case svc.Stop, svc.Shutdown:
            
                testOutput := strings.Join(args, "-")
                testOutput += fmt.Sprintf("-%d", c.Context)
                elog.Info(1, testOutput)
                break loop
            case svc.Pause:
                changes <- svc.Status{State: svc.Paused, Accepts: cmdsAccepted}
    
            case svc.Continue:
                changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
    
            default:
                elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
            }
        }
    }
    changes <- svc.Status{State: svc.StopPending}
    return

Checklist清单

librdkafka Version: 1.7.0 confluent-kafka-go Version:1.7.0 golang.org/x/sys v0.0.0-20210615035016 librdkafka 版本:1.7.0 confluent-kafka-go 版本:1.7.0 golang.org/x/sys v0.0.0-20210615035016

Finally I made it work.最后我让它工作了。 The only part that was missing was compile in a static way like this => go build -ldflags '-extldflags "-static"'.唯一缺少的部分是像这样以静态方式编译 => go build -ldflags '-extldflags "-static"'。 This fixed the issue with a missing dll, the problem was that on console everything works fine.这解决了缺少 dll 的问题,问题是在控制台上一切正常。 I never see the missing dll.我从来没有看到丢失的 dll。 But when I work on a window server 2016 the console did not run.但是当我在窗口服务器 2016 上工作时,控制台没有运行。 The specific error was "Run bin file Systerm Error "libwinpthread-1.dll was not found". I fix thats with static compile and came back to prove the window service with this compilation too. And finally i have my go service running as window service and using confluent kafka librery.具体错误是“运行 bin 文件系统错误”libwinpthread-1.dll 未找到“。我用静态编译修复了这个问题,然后回来证明这个编译的窗口服务。最后我让我的 go 服务作为窗口运行服务和使用融合的 kafka 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 confluent-kafka-go 中创建具有多个消费者的消费者组? - how to create consumer group with multiple consumers in confluent-kafka-go? 在Linux上使用confluent-kafka-go构建Go应用程序 - Building Go Application using confluent-kafka-go on Linux 如何使用confluent-kafka-go获取kafka代理错误的事件 - How to get events for kafka broker errors using confluent-kafka-go 我们如何使用 confluent-kafka-go 客户端确保可靠和低延迟的 kafka 编写? - How can we ensure reliable and low-latency kafka writing using confluent-kafka-go client? 具有 confluent-kafka-go 更改偏移量的 kafka 消费者 - kafka consumer with confluent-kafka-go change offset Kafka 消费者抵消导出 golang -- sharma 或 confluent-kafka-go lib - Kafka consumer offset export golang -- sharma or confluent-kafka-go lib librdkafka 和 confluent-kafka-go 是否支持基于 JKS 的 SSL 配置? - Does librdkafka and confluent-kafka-go supports JKS based SSL Configuration? 如何使用 Segmentio 的 kafka-go 创建 Kafka 主题? - How to create Kafka topic using Segmentio's kafka-go? 在融合的 kafka go 中读取来自 kafka 主题的消息时如何使用确认? - How to use acknowledgement when reading messages from kafka topic in confluent kafka go? Confluent kafka go 客户端 memory 泄漏 - Confluent kafka go client memory leak
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM