{"id":7367,"date":"2023-08-13T23:23:58","date_gmt":"2023-08-13T22:23:58","guid":{"rendered":"https:\/\/rakhesh.com\/?p=7367"},"modified":"2023-08-13T23:23:58","modified_gmt":"2023-08-13T22:23:58","slug":"notes-on-event-hubs","status":"publish","type":"post","link":"https:\/\/rakhesh.com\/azure\/notes-on-event-hubs\/","title":{"rendered":"Notes on Event Hubs"},"content":{"rendered":"
I had been using Event Hubs + Azure Functions pretty naively for the past few months. Mainly coz I just assumed how some of the things work, and also coz I guess when working with the cloud<\/em> you have this mindset that things just work and don’t really care about the details.<\/p>\n Anyways.<\/p>\n The first thing is that I have this Function that does some processing, and if it fails I was pushing the item to an event hub thus:<\/p>\n The expectation being that if the push fails I can output it and also do something like email me the item for instance. But this doesn’t work coz you can’t put the The way I encountered this was because I copy pasted some event hub bindings between two of my Functions without realizing I was copying the wrong code. The Function I was copying from had event hub triggers, while the Function I copied to had it as output and as you can see they have differences:<\/p>\ntry {\r\n Push-OutputBinding -Name eventHubMessages -Value $body -ErrorAction Stop\r\n} catch {\r\n Write-Host \"=== Error pushing ===\"\r\n # do something about it...\r\n}<\/pre>\n
Push-OutputBinding<\/code> in a
try\/ catch<\/code> block. I never tested whether this works or not, and always assumed it does, until I was testing something this weekend and realized the exceptions when pushing weren’t being caught. That’s because all output bindings are executed after a Function exits<\/a> and is done by the Function host\/ worker, not the Function itself.<\/p>\n