简体   繁体   中英

How edit EvenData message in Receiver Event Hub?

I'm a beginner and I have a problem. I can not replace the individual message in my receiver event hub. Does anyone know a way how I can fix this?

 public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
    {


            try
        {
            foreach (EventData message in messages)
            {
                    string data = Encoding.UTF8.GetString(message.GetBytes());
                    NewClient Client = JsonConvert.DeserializeObject<NewClient>(data);
                    GPSApi Gpsobject = new GPSApi();
                    Gpsobject.GetJson(Client.City, Client.Street);
                    Gpsobject.DeserializeJson();
                    Gpsobject.ConvertJson();
                    WeatherApi WeatherApiobject = new WeatherApi();
                    WeatherApiobject.GetJson(Gpsobject.convertlat, Gpsobject.convertlng);
                    data = WeatherApiobject.sendEvent;
                    EventData data1 = new EventData(Encoding.UTF8.GetBytes(data));
                    //message = data1;
                // LUB TUTAJ                    
                Interlocked.Increment(ref this.totalMessages);
                this.LastMessageOffset = data1.Offset;
            }

I've tried loop. eg

(int i=0; i<messages.Count(); i++)

Also not working.

I would after receiving customer data in the message, then download it to the weather, and replace the message of the weather, which continue to be sent to the stream analytics.

I do not think this is possible. You are processing messages using an EventProcessor . That's the end of line when it comes to the event stream. From here you can do something with the data like persisting it or whatever but you cannot alter/overwrite the events and then somehow magically put them back in the same event hub stream.

It would be nearly impossible to implement because how could you deal when multiple consumers are reading the stream using different Consumer Groups, and what to do if those consumers are at other positions in the stream?

You have some options though:

  1. In the Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages) loop all messages like you do now and send them to another event hub which is then in turn connected to a Stream Analytics Job.
  2. Using the Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages) loop all messages like you do now, get the weather data and store that to Azure Blob Storage.

If you go explore option 2 you can connect the blob container as an input to the Stream Analytics Job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM