Exemplo n.º 1
0
    def on_message(self, connMgr, message):

        try:
            # Display the XML representation of the received message
            libgmsec_python3.log_info(
                "[ExampleCallback:on_message] Received:\n" + message.to_XML())

            # Construct Reply subject.
            component = ""

            try:
                component = message.get_string_field("COMPONENT").get_value()

            except GmsecError as e:
                libgmsec_python3.log_warning(
                    "COMPONENT field is not available: " + str(e))

            # Set Status Code to indicate Successful Completion.
            # The GMSEC Interface Specification Document defines 6
            # unique STATUS-CODE values:
            # 1 - Acknowledgement
            # 2 - Working/keep alive
            # 3 - Successful completion
            # 4 - Failed completion
            # 5 - Invalid request
            # 6 - Final message
            # If an asynchronous requestor is awaiting a reply, the
            # ReplyCallback in use will remain active for multiple
            # messages, so long as the messages it receives contain
            # a STATUS-CODE of either 1 or 2.
            status_code = "3"

            # Create the reply subject.
            # See API Interface Specificaiton Document for
            # more information on Reply Message subjects.
            # Generally speaking, they are composed
            # accordingly:
            # [Spec].[Mission].[Satellite ID].
            # [Message Type].[Component Name].[Status Code]

            reply_subject = "GMSEC.MISSION.SAT_ID.RESP.REPLY_ASYNC." + status_code

            reply = libgmsec_python3.Message(reply_subject,
                                             libgmsec_python3.Message.REPLY)

            # Add fields to the reply message
            reply.add_field("COMPONENT", component)
            reply.add_field("ANSWER", "Sure looks like it!")

            # Display XML representation of reply message
            libgmsec_python3.log_info("Prepared Reply:\n" + reply.to_XML())

            # Send Reply
            connMgr.reply(message, reply)

            self.replySent = True

        except libgmsec_python3.GmsecError as e:
            libgmsec_python3.log_error("[ExampleCallback::on_message] " +
                                       str(e))
Exemplo n.º 2
0
def publishTestMessage(connMgr, subject):

    i = 123

    # Create a Message object
    message = libgmsec_python3.Message(subject,
                                       libgmsec_python3.Message.PUBLISH)

    # Add fields to the Message
    message.add_field("F", False)
    message.add_field(libgmsec_python3.I32Field("I", i))
    message.add_field(libgmsec_python3.U16Field("K", i))
    message.add_field("S", "This is a test")
    message.add_field(libgmsec_python3.F32Field("D", 1 + 1. / i))
    message.add_field(libgmsec_python3.BinaryField("X", "JLMNOPQ", 7))

    # Publish Message
    connMgr.publish(message)

    # Output the Message's XML string representation by invoking Log macro
    libgmsec_python3.log_info("Sent:\n" + message.to_XML())
Exemplo n.º 3
0
def buildMessage(config, numFields):

    msg = libgmsec_python3.Message("GMSEC.SYSTEST.TEST.REQ.DIR.LONG",
                                   libgmsec_python3.Message.PUBLISH, config)

    if (numFields > 0):

        # Add Fields
        for i in range(0, numFields):

            fieldName = "FIELD-"

            if i < 10:
                fieldName += "00"
            elif i < 100:
                fieldName += "0"
            else:
                fieldName += ""

            msg.add_field(fieldName, i)

        return msg
Exemplo n.º 4
0
def main():

    if (len(sys.argv) <= 1):
        usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>"
        print(usageMessage)
        return -1

    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)

    # Print the GMSEC API version number using the GMSEC Logging
    # interface
    # This is useful for determining which version of the API is
    # configured within the environment
    libgmsec_python3.log_info(libgmsec_python3.Connection.get_API_version())

    try:
        # Create the ConnectionManager
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Open the connection to the middleware
        connMgr.initialize()

        # Output middleware client library version
        libgmsec_python3.log_info(connMgr.get_library_version())

        # Output information
        libgmsec_python3.log_info(
            "Issuing a request using the DEFAULT_REQUEST_SUBJECT '" +
            DEFAULT_REQUEST_SUBJECT + "'")

        # Create message
        requestMsg = libgmsec_python3.Message(DEFAULT_REQUEST_SUBJECT,
                                              libgmsec_python3.Message.REQUEST)

        # Add fields to message
        requestMsg.add_field("QUESTION", "Is there anyone out there?")
        requestMsg.add_field("COMPONENT", "request")

        # Display XML representation of request message
        libgmsec_python3.log_info("Sending request message:\n" +
                                  requestMsg.to_XML())

        # Send Request Message
        # Timeout periods:
        # -1 - Wait forever
        # 0 - Return immediately
        # >0 - Time in milliseconds before timing out
        replyMsg = connMgr.request(requestMsg,
                                   libgmsec_python3.GMSEC_WAIT_FOREVER)

        # Example error handling for calling request() with a timeout
        if (replyMsg):
            # Display the XML string representation of the reply
            libgmsec_python3.log_info("Received replyMsg:\n" +
                                      replyMsg.to_XML())

            # Destroy the replyMsg message
            connMgr.release(replyMsg)

        # Disconnect from the middleware and clean up the Connection
        connMgr.cleanup()

    except GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Exemplo n.º 5
0
def main():

    if (len(sys.argv) <= 1):
        usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>"
        print(usageMessage)
        return -1

    cb = AsyncStatusCheckCallback()

    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)

    # Toggle the WebSphere MQ client libraries-level asynchronous publish
    # functionality on
    config.add_value("MW-ASYNC-PUBLISH", "true")

    # Toggle the periodic WebSphere MQ asynchronous publish status report
    # functionality on.  The GMSEC API Connection will periodically fire
    # off an Event which will trigger the on_event function of an
    # EventCallback registered to the event labeled,
    # Connection::WSMQ_ASYNC_STATUS_CHECK_EVENT
    config.add_value("MW-ASYNC-STATUS-CHECK", "true")

    # Additionally, the "MW-ASYNC-STATUS-CHECK-MESSAGE-INTERVAL"
    # configuration option can be used to instruct the GMSEC Connection
    # on how frequently (in number of publish operations) it should
    # periodically fire the WSMQ_ASYNC_STATUS_CHECK_EVENT. By default, it
    # will fire once every 100 messages.
    # For the sake of this example, we will use 500 messages.
    config.add_value("MW-ASYNC-STATUS-CHECK-MESSAGE-INTERVAL", "500")

    # Print the GMSEC API version number using the GMSEC Logging
    # interface
    libgmsec_python3.log_info(
        libgmsec_python3.ConnectionManager.get_API_version())

    try:
        # Create the Connection
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Connect
        connMgr.initialize()

        # Register the event callback with the connection to catch
        # the WebSphere asynchronous publish status events which are
        # eminated from the API
        connMgr.register_event_callback(
            libgmsec_python3.Connection.WSMQ_ASYNC_STATUS_CHECK_EVENT, cb)
        # Output middleware version
        libgmsec_python3.log_info("Middleware version = " +
                                  connMgr.get_library_version())

        libgmsec_python3.log_info("Publishing messages using the subject: " +
                                  EXAMPLE_MESSAGE_SUBJECT)

        # Create a GMSEC Message object
        message = libgmsec_python3.Message(EXAMPLE_MESSAGE_SUBJECT,
                                           libgmsec_python3.Message.PUBLISH)

        # Publish message as quickly as possible
        # (i.e. No sleep operation between each publish operation)
        count = 0
        while (not cb.eventFired):
            # Populate the Message with fields, increment a
            # counter so that a publisher can track how many
            # messages were published (if they are interested)
            count += 1
            populateMessage(message, count)

            # Publish the message to the middleware bus
            connMgr.publish(message)

            # Note: We do not recommend printing the output of a
            # message when publishing it while using the WebSphere
            # async publish functionality, as it is
            # counter-intuitive to take take up CPU resources
            # performing I/O operations when attempting to achieve
            # high message throughput rates. As such, if you want
            # to analyze the messages published by this program,
            # we recommend you execute GMSEC_API/bin/gmsub to
            # receive the messages.

        libgmsec_python3.log_info(
            "Event detected, ending example demonstration")

        # Clean up the ConnectionManager before exiting the program
        connMgr.cleanup()

    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Exemplo n.º 6
0
def main():

    if (len(sys.argv) <= 1):
        usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>"
        print(usageMessage)
        return -1

    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)

    # Print the GMSEC API version number using the GMSEC Logging
    # interface
    # This is useful for determining which version of the API is
    # configured within the environment
    libgmsec_python3.log_info(
        libgmsec_python3.ConnectionManager.get_API_version())

    try:
        # Create a ConnectionManager object
        # This is the linchpin for all communications between the
        # GMSEC API and the middleware server
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Open the connection to the middleware
        libgmsec_python3.log_info(
            "Opening the connection to the middleware server")
        connMgr.initialize()

        # Output middleware client library version
        libgmsec_python3.log_info(connMgr.get_library_version())

        libgmsec_python3.log_info(
            "Publishing two messages -- One will be received by the subscriber the other will be filtered out"
        )

        # Create a message which will be received by the subscriber
        # in this set of example programs

        message = libgmsec_python3.Message(EXAMPLE_MESSAGE_SUBJECT,
                                           libgmsec_python3.Message.PUBLISH)
        populateMessage(message)
        # Publish the message to the middleware bus
        connMgr.publish(message)

        # Display the XML string representation of the Message for
        # the sake of review
        libgmsec_python3.log_info("Published message:\n" + message.to_XML())

        # Create a message which will NOT be received by the subscriber
        # in this set of example programs

        message = libgmsec_python3.Message(FILTERED_MESSAGE_SUBJECT,
                                           libgmsec_python3.Message.PUBLISH)
        populateMessage(message)

        # Publish the message to the middleware bus
        connMgr.publish(message)

        # Display the XML string representation of the Message for
        # the sake of review
        libgmsec_python3.log_info("Published message:\n" + message.to_XML())

        # Disconnect from the middleware and clean up the Connection
        connMgr.cleanup()

    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Exemplo n.º 7
0
binField = lp.BinaryField('BIN-FIELD-1', blob, len(blob))

print("\nBinaryField...\n")
print("Field Name is    : " + binField.get_name())
print("Field Type is    : " + str(binField.get_type()))
print("Field Len        : " + str(binField.get_length()))
print("Field as string  : ")
print(binField.get_string_value())
print("Field as raw data:")
binData = binField.get_value()
print(binascii.hexlify(binData))
print("\n")

# 2. Create Message and add existing BinaryField, and an anonymous one
#
msg = lp.Message('GMSEC.FOO.BAR', lp.Message.PUBLISH)
msg.add_field(binField)
msg.add_field("BIN-FIELD-2", blob, len(blob))

# 3. Retrieve Field(s) from the Message
#
msgFieldIter = msg.get_field_iterator()

print("BinaryField from the Message...\n")
while msgFieldIter.has_next():
    msgField = msgFieldIter.next()

    print("Field Name is    : " + msgField.get_name())
    print("Field Type is    : " + str(msgField.get_type()))

    if msgField.get_type() == lp.Field.BIN_TYPE:
Exemplo n.º 8
0
def main():

    if(len(sys.argv) <= 1):
        usageMessage = "usage: " +  sys.argv[0] + " mw-id=<middleware ID>"
        print(usageMessage)
        return -1


    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)

    # Output GMSEC API version
    libgmsec_python3.log_info(libgmsec_python3.ConnectionManager.get_API_version())

    try:
        # Create the Connection
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Open the connection to the middleware
        libgmsec_python3.log_info("Opening the connection to the middleware server")
        connMgr.initialize()

        # Output middleware client/wrapper version
        libgmsec_python3.log_info(connMgr.get_library_version())

        connMgr.subscribe(DEFAULT_REQUEST_SUBJECT)
        libgmsec_python3.log_info("Subscribed to: " + DEFAULT_REQUEST_SUBJECT);

        # Call receive() to synchronously retrieve a message that has
        # been received by the middleware client libraries
        # Timeout periods:
        # -1 - Wait forever
        #  0 - Return immediately
        # >0 - Time in milliseconds before timing out
        requestMsg = connMgr.receive(-1)

        # Example error handling for calling receive() with a timeout
        if (requestMsg):
                
            # Display the XML representation of the received message
            libgmsec_python3.log_info("Received a message\n" + requestMsg.to_XML())

            # Double-check the Message type to ensure that it is a request
            if (requestMsg.get_kind() == libgmsec_python3.Message.REQUEST):
                            
                # Get the name of the component who issued the request
                component = 0

                # Construct a Reply message
                try:
                    compField = requestMsg.get_string_field("COMPONENT")
                    component = compField.get_value()
                                
                except GmsecError as e:
                     libgmsec_python3.log_error(str(e))
                                

                # Set Status Code to indicate Successful Completion.
                # The GMSEC Interface Specification Document defines 6
                # unique STATUS-CODE values:
                # 1 - Acknowledgement
                # 2 - Working/keep alive
                # 3 - Successful completion
                # 4 - Failed completion
                # 5 - Invalid request
                # 6 - Final message
                # If an asynchronous requestor is awaiting a reply, the
                # ReplyCallback in use will remain active for multiple
                # messages, so long as the messages it receives contain
                # a STATUS-CODE of either 1 or 2.
                status_code = "3"

                # Set the reply subject.
                # See API Interface Specificaiton Document for
                # more information on Reply Message subjects.
                # Generally speaking, they are composed
                # accordingly:
                # [Spec].[Mission].[Satellite ID].
                # [Message Type].[Component Name].[Status Code]
                               
                reply_subject = "GMSEC.MISSION.SAT_ID.RESP.REPLY." + status_code

                # Create reply message
                replyMsg = libgmsec_python3.Message(reply_subject, libgmsec_python3.Message.REPLY)

                # Add fields to the reply message
                replyMsg.add_field("ANSWER", "Yup, I'm here!")
                replyMsg.add_field("COMPONENT", component)

                # Display XML representation of the reply message
                libgmsec_python3.log_info("Prepared Reply:\n" + replyMsg.to_XML())

                # Send Reply
                connMgr.reply(requestMsg, replyMsg)

            # Destroy request message to release its memory
            connMgr.release(requestMsg)

        connMgr.cleanup()
                
        
    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1
        
    return 0
Exemplo n.º 9
0
def main():

    if(len(sys.argv) <= 1):
        usageMessage = "usage: " +  sys.argv[0] + " mw-id=<middleware ID>"
        print(usageMessage)
        return -1


    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)

    # Output GMSEC API version
    libgmsec_python3.log_info(libgmsec_python3.Connection.get_API_version())

    try:
        # Create the Connection
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Connect
        connMgr.initialize()

        # output connection middleware version
        libgmsec_python3.log_info(connMgr.get_library_version())

        # Create request message
        requestMsg = libgmsec_python3.Message(DEFAULT_REQUEST_SUBJECT, libgmsec_python3.Message.REQUEST)

        # Add fields to request message
        requestMsg.add_field("QUESTION", "Does the request/reply functionality still work?")
        requestMsg.add_field("COMPONENT", "request_async")

        # Display XML representation of request message
        libgmsec_python3.log_info("Requesting:\n" + requestMsg.to_XML())

        cb = ExampleReplyCallback()
        connMgr.request(requestMsg, libgmsec_python3.GMSEC_WAIT_FOREVER, cb)

        libgmsec_python3.log_info("Waiting for response...")

        # Loop while waiting for the asynchronous response until done
        while (cb.receivedReply == 0):
            libgmsec_python3.TimeUtil.millisleep(100)
                
        if (cb.receivedReply):
            libgmsec_python3.log_info("Response Received!")
        else:
            libgmsec_python3.log_warning("No response received")

        connMgr.cleanup()
            
    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1
        
    return 0
Exemplo n.º 10
0
def main():

    if (len(sys.argv) <= 1):
        usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>"
        print(usageMessage)
        return -1

    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)

    # Print the GMSEC API version number using the GMSEC Logging
    # interface
    # This is useful for determining which version of the API is
    # configured within the environment
    libgmsec_python3.log_info(
        libgmsec_python3.ConnectionManager.get_API_version())

    try:

        # Create a ConnectionManager object
        # This is the linchpin for all communications between the
        # GMSEC API and the middleware server
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Open the connection to the middleware
        libgmsec_python3.log_info(
            "Opening the connection to the middleware server")
        connMgr.initialize()

        # Output middleware client library version
        libgmsec_python3.log_info(connMgr.get_library_version())

        # Create a message
        # Disclaimer: This message is not based off of a Message
        # Definition outlined by the GMSEC Interface
        # Specification Document (ISD).  It is meant to be an example
        # to demonstrate the various capabilities of the GMSEC Message
        # and Field classes. The GMSEC Team recommends that you map
        # your data into the Messages defined in the GMSEC ISD, as
        # doing so will make your software "GMSEC Compliant" resulting
        # in plug-and-play type functionality with other GMSEC
        # compliant software.
        message = libgmsec_python3.Message(EXAMPLE_MESSAGE_SUBJECT,
                                           libgmsec_python3.Message.PUBLISH)
        populateMessage(message)

        # Publish the message to the middleware bus
        connMgr.publish(message)

        # Display the XML string representation of the Message for
        # the sake of review
        libgmsec_python3.log_info("Published message:\n" + message.to_XML())

        # Disconnect from the middleware and clean up the Connection
        connMgr.cleanup()

    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0
Exemplo n.º 11
0
def main():

    if(len(sys.argv) <= 1):
        usageMessage = "usage: " + sys.argv[0] + " mw-id=<middleware ID>" 
        print(usageMessage)
        return -1


    # Load the command-line input into a GMSEC Config object
    # A Config object is basically a key-value pair map which is used to
    # pass configuration options into objects such as Connections,
    # ConnectionManagers, Subscribe and Publish function calls, Messages,
    # etc.
    config = libgmsec_python3.Config(sys.argv)

    # Enable Message Binning
    config.add_value("GMSEC-USE-MSG-BINS", "true")

    # Specify the number of messages to be aggregated prior to publishing
    # the aggregate message to the middleware server (This applies to all
    # of the messages which match the subject(s) provided in the
    # GMSEC-MSG-BIN-SUBJECT-N configuration parameters
    # Note: The aggregate message will be sent to the middleware server
    # immediately upon this many messages being published, regardless of
    # the value supplied for GMSEC-MSG-BIN-TIMEOUT.
    config.add_value("GMSEC-MSG-BIN-SIZE", "10")

    # Specify a timeout (in milliseconds) for the aggregate message to be
    # sent to the middleware server
    # Note: The aggregate message will be sent to the middleware server
    # after this period of time if the message bin does not fill up (per
    # the value provided for GMSEC-MSG-BIN-SIZE) prior to this timeout
    config.add_value("GMSEC-MSG-BIN-TIMEOUT", "5000")

    # Specify the subjects to aggreate messages for.
    # Note: Subscription wildcard syntax can be used here, and has been
    # supported since GMSEC API version 4.3.
    config.add_value("GMSEC-MSG-BIN-SUBJECT-1", "GMSEC.*.PUBLISH")

    # Specify any subjects that should be excluded from being aggregated
    # This is useful if a wildcard subscription is provided in one of the
    # GMSEC-MSG-BIN-SUBJECT-N parameters.
    config.add_value("GMSEC-MSG-BIN-EXCLUDE-SUBJECT-1", EXAMPLE_BIN_EXCLUDE_SUBJECT)

    # Since this example program uses an invalid message, we ensure the
    # validation check is disabled.
    config.add_value("gmsec-msg-content-validate-all", "false")

    # If it was not specified in the command-line arguments, set LOGLEVEL
    # to 'INFO' and LOGFILE to 'stdout' to allow the program report output
    # on the terminal/command line
    initializeLogging(config)
    # Print the GMSEC API version number using the GMSEC Logging
    # interface
    # This is useful for determining which version of the API is
    # configured within the environment
    libgmsec_python3.log_info(libgmsec_python3.ConnectionManager.get_API_version())

    try:
        # Create a ConnectionManager object
        # This is the linchpin for all communications between the
        # GMSEC API and the middleware server
        connMgr = libgmsec_python3.ConnectionManager(config)

        # Open the connection to the middleware
        libgmsec_python3.log_info("Opening the connection to the middleware server")
        connMgr.initialize()

        # Output middleware client library version
        libgmsec_python3.log_info(connMgr.get_library_version())

                
        # Create a message 
        message = libgmsec_python3.Message(EXAMPLE_MESSAGE_SUBJECT, libgmsec_python3.Message.PUBLISH)

        for i in range(0,5):
            populateMessage(message, i+1)

            # Publish the message to the middleware bus
            connMgr.publish(message)

            # Display the XML string representation of the Message for
            # the sake of review
            libgmsec_python3.log_info("Published message: " + message.to_XML())

        # Create another message
        message = libgmsec_python3.Message(EXAMPLE_BIN_EXCLUDE_SUBJECT, libgmsec_python3.Message.PUBLISH)

        populateMessage(message, 1)

        # Publish the message to the middleware bus
        # Note: When calling publish(), if a message does NOT match
        # one of the subjects to be aggregated, it will be immediately
        # published
        connMgr.publish(message)

        # Display the XML string representation of the Message for
        # the sake of review
        libgmsec_python3.log_info("Published message: " + message.to_XML())
                

        # Disconnect from the middleware and clean up the Connection
        connMgr.cleanup()
        
    except libgmsec_python3.GmsecError as e:
        libgmsec_python3.log_error(str(e))
        return -1

    return 0