简体   繁体   English

.NET Web Core 5 API - 如何使用来自 Linux 服务器的 Kafka 消息?

[英].NET Web Core 5 API - How can I consume Kafka messages from my Linux server?

I made a Linux virtual machine that is running Kafka.我做了一个运行 Kafka 的 Linux 虚拟机。 I tested the producer and was able to consume it from my other computer.我测试了生产者并且能够从我的另一台计算机上使用它。 Now I want to make a consumer that runs in my API that I'm working on.现在我想创建一个在我正在处理的 API 中运行的消费者。

I'm trying to follow some tutorials, but they are confusing.我正在尝试遵循一些教程,但它们令人困惑。 I want to just run a consumer that will read the messages from the producer in my project.我只想运行一个消费者,它将在我的项目中读取来自生产者的消息。 I downloaded the Confluent.Kafka package. Then I tried making a Services/ProcessOrdersService.cs file like so:我下载了 Confluent.Kafka package。然后我尝试制作一个 Services/ProcessOrdersService.cs 文件,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using System.Threading;
using POS.Models;
using Newtonsoft.Json;
using Confluent.Kafka;

namespace POS.Services
{
    public class ProcessOrdersService
    {

        private readonly ConsumerConfig consumerConfig;

        public ProcessOrdersService(ConsumerConfig consumerConfig)
        {
            this.consumerConfig = consumerConfig;
        }
    }
}

But I'm confusing on what to do after this?但是我对这之后该怎么办感到困惑? Can anyone point me in the right direction?谁能指出我正确的方向? I've tried looking at some tutorials but I don't understand where things are supposed to go within my Web Core 5 API project.我试过查看一些教程,但我不明白 go 在我的 Web Core 5 API 项目中应该在哪里。

Thank you for any help.感谢您的任何帮助。 :D :D

You may find my article helpful: I provided comprehensive instructions on how to consume from C# and explained a couple of subtle points.您可能会发现我的文章很有帮助:我提供了关于如何使用 C# 的全面说明,并解释了几个细微的要点。

If you have any questions, feel free to ask!如果你有任何问题随时问!

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

相关问题 为什么我不能从我的 Xamarin 应用程序发布到我的 .net 核心 web Z8A5DA52ED1264E47D8A35 - Why can't I post from my Xamarin Frorms app to my .net core web api 如何在.Net中与不同类型的使用者一起使用RabbitMq消息? - How can I consume RabbitMq messages with different type of consumers in .Net? 从 API .NET CORE 消费 API - Consume API from API .NET CORE 如何包装 Web API 响应(在 .net core 中)以保持一致性? - How can I wrap Web API responses(in .net core) for consistency? 如何将图像从 UWP 发布到 .NET core web api? - How can I post image from UWP to .NET core web api? 如何在 ASP.NET Core 5 Web API 中绑定来自请求主体的简单类型 - How can I bind simple type coming from body of the request in ASP.NET Core 5 Web API 如何在 ASP.NET Core 6 Web API 中以像素形式获取图像内容并从中创建图像? - How can I get image content as pixel and create image from it in ASP.NET Core 6 Web API? 如何从 ASP.NET Core Web API 向客户端发送 JSON 响应? - How can I send JSON response to client from ASP.NET Core Web API? 我需要创建一个我的 .Net Core 项目可以连接到的 .Net Web API 项目,但我使用的是 Mac - I need to create a .Net Web API project that my .Net Core project can connect to, but I'm on a Mac ASP.NET 核心 Web API - 如何使用第 3 方 API 基于条件 - ASP.NET Core Web API - How to Consume 3rd party API Based on Condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM