How can I tell if my program is not entitled to publish to a topic?

Most AMPS applications are designed for maximum throughput, which includes carefully testing entitlements for publishers and subscribers before deployment and minimizing the amount of work that clients do when publishing a message. However, this also means that it's rare for publishes to fail, and a failure in publication usually represents a critical error.

Managing Acknowledgements

When the topic being published to uses a transaction log, AMPS optimizes the acknowledgement messages by conflating the acknowledgements. This means that, rather than acknowledging every message when publishes succeed, AMPS acknowledges multiple publishes at a time.

When the topic being published to does not use a transaction log, requesting acknowledgements for a publish means that AMPS returns an acknowledgement message for each publish, which consumes both network and processing resources. 60East recommends carefully planning which messages require acknowledgement.

Consider whether failure acknowledgements are required for your application, and whether each message requires an acknowledgement, or whether your application can request acknowledgement on the first message to a topic, or request a message at a set interval (for example, every 1000 messages).

Client versions 5.0 and later

In current versions of the AMPS Client, you can register a FailedWriteHandler to receive information about messages that could not be published, including entitlement failures. This is the most convenient way to be notified of errors, and is the recommended approach.

Older client versions

For older versions of the AMPS Client, you can use the technique described below.

There are two steps required to detecting entitlement errors.

  1. Register a LastChanceMessageHandler to process error acknowledgements as they are returned.

  2. Request an acknowledgement on the publish command that will report entitlement errors.

    By default, the AMPS clients do not request acknowledgements to verify that a publish succeeded. The HA Client requests persisted acknowledgements, which it uses to determine when it is safe to remove messages from the publish store. The simple Client does not request acknowledgements on a publish.

With these two steps, your application will receive notification from AMPS when a publish fails.

The sample below shows a simple way to register for and receive not entitled notifications using the Python client.


    import AMPS
    import time
     
    def handleUnexpected(message):
      print message.get_status(),message.get_reason()
      # logging or recovery logic here
     
    c = AMPS.Client("pub-ack-test")
    c.connect("tcp://testuser@localhost:9004/nvfix")
     
    c.set_last_chance_message_handler(handleUnexpected)
     
    # Request completed ack for a publish message
    m = c.allocate_message()
    m.set_command("publish")
    m.set_ack_type("completed")
    m.set_topic("test-topic")
    m.set_data("y=1")
     
    c.send(m)

    time.sleep(10)

``` 

 

 

 Keywords: entitlement failure, message acknowledgements, ack, failure
ack, handling publish failure, publish notifications, failed publish

Last updated