Skip to content

Receive message from Service bus without deleting from Queue - Unity 3D #2

@SurajMK94

Description

@SurajMK94

Hi Team,

Thank you for providing the the source code for Service bus communication via unity.

When I tried to listen the message from the service bus, the messages are coming in client. But they are getting deleted from the Service bus. When I checked in Microsoft forums, I saw an approach called "Non destructive receive". Could you please guide me how to achieve it in Unity 3D.

Below is my function:

private void ListenForMessages()
{
if (_isRunning != null && !_isRunning.IsCompleted)
return;

    var address = listenMessageURL + "/subscriptions/notification/messages/head?timeout=60";

    try
    {
        WebRequest request = WebRequest.Create(address);

        if (_sasProvider == null)
        {
            _sasProvider = new SharedAccessSignatureTokenProvider(issuerName, issuerSecret, new TimeSpan(1, 0, 0));
        }

        var token = _sasProvider.GetToken(listenMessageURL, "POST", new TimeSpan(1, 0, 0)); // realm
        request.Headers[HttpRequestHeader.Authorization] = token.TokenValue;

        request.Method = "DELETE";
        RequestState rs = new RequestState();
        rs.Request = request;

        _isRunning = request.BeginGetResponse(new AsyncCallback(RespCallback), rs);
    }
    catch (WebException ex)
    {
        // if the server has not created a topic yet for the client then a 404 error will be returned so do not report
        if (!ex.Message.Contains("The remote server returned an error: (404) Not Found"))
            if (OnListenError != null)
                OnListenError.Invoke(this, new System.IO.ErrorEventArgs(ex));
    }
    catch (Exception ex)
    {
        if (OnListenError != null)
            OnListenError.Invoke(this, new System.IO.ErrorEventArgs(ex));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions