azureazure-eventhub

How do i modify message retention period in Azure Event Hub?


When searching for a way to change the retention period of an Event Hub Instance (without deleting it, and recreating it) i come up very short on material. There are references that this was possible - including a Microsoft Blog Entry, here: https://techcommunity.microsoft.com/t5/messaging-on-azure-blog/data-retention-in-event-hubs/ba-p/370660 (and follow up posts in Stack Overflow, with no actual example on how to do so!)

I'm looking to increase from 1 day, upwards to 7, but there appears to be no way to do this in the Azure Portal, and with no documentation i've no idea how to do it. It looks like it should be a case of modifying the "messageRetentionInDays" item in the ARM template, and redeploying in the update mode (rather than teardown + redeploy). However, with no docs, and nobody else confirming, i do not want to experiment.

Any ideas / docs i've missed, or your own experience?


Solution

  • There are numerous way to update the retention period. ARM/Bicep is an excellent choice, otherwise there are:

    Azure CLI

    az eventhubs eventhub update --resource-group myresourcegroup --namespace-name mynamespace --name myeventhub --message-retention 3
    

    (doc)

    Rest Api

    You can leverage the rest api to update the event hub, for example

    PUT https://your-namespace.servicebus.windows.net/your-event-hub?timeout=60&api-version=2014-01 HTTP/1.1  
    Authorization: SharedAccessSignature sr=your-namespace.servicebus.windows.net&sig=tYu8qdH563Pc96Lky0SFs5PhbGnljF7mLYQwCZmk9M0%3d&se=1403736877&skn=RootManageSharedAccessKey  
    Content-Type: application/atom+xml;type=entry;charset=utf-8  
    Host: your-namespace.servicebus.windows.net
    If-Match: *
    Content-Length: 264  
    Expect: 100-continue  
    Connection: Keep-Alive  
      
    <entry xmlns='http://www.w3.org/2005/Atom'>  
      <content type='application/xml'>  
        <EventHubDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">  
          <MessageRetentionInDays>3</MessageRetentionInDays>  
        </EventHubDescription>  
      </content>  
    </entry>  
    

    (doc)

    Powershell

    $loggingEventHub = Get-AzEventHub -ResourceGroupName $ehResourceGroup -Namespace $ehNameSpace -Name $ehName
    
    $loggingEventHub.MessageRetentionInDays = 5
    
    Set-AzEventHub -ResourceGroupName $ehResourceGroup -Namespace $ehNameSpace -Name $ehName -InputObject $loggingEventHub
    

    (doc)