IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
  • 1.  C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/23/17 10:34 AM

    I try to use the webMethods broker to get messages from an java jms broker.
    This system is distributed by a partner of my client, to whom I don’t have access. I haven’t been able to consume messages, because the message are returned as BytesMessage. How i can read the message and convert to a knowed type or to a string.


    #broker
    #Integration-Server-and-ESB
    #webMethods
    #Universal-Messaging-Broker


  • 2.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/23/17 12:45 PM

    Hi Rui,

    what about exploring the Built-In-Services Guide for your wM version?

    BTW:
    Which versions of wM IS and Broker are you using?

    Can you describe your scenario a bit more in detail please?

    Regards,
    Holger


    #webMethods
    #broker
    #Universal-Messaging-Broker
    #Integration-Server-and-ESB


  • 3.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/24/17 02:23 PM

    I don’t know the version of wV. My client only gave me the Broker, ClientId, Destination and the instrunctions to create a session with a CreateDurableSubscriber. I can create the connection, create the session, initialize the connection and start receiving messages. However i can’t read the body massage.

    In the example below the msg is a BytesMessage, that i can’t extract the body message or convert to a string. Browsing the webMethods.Msg, i can’t found a way to obtain the message. BytesMessages are a type i cant convert into a string.

    SAMPLE:

    // get a destination
    IDestination destination = isQueue ? MsgFactory.GetQueue(“SampleQueue”) : MsgFactory.GetTopic(props.DestinationName);

            // get a connection factory
    IConnectionFactory connectionFactory = MsgFactory.GetConnectionFactory(props.Broker, props.ClientID);
    
    using (IConnection connection = connectionFactory.CreateConnection())
    {
    
    using (ISession session = connection.CreateSession(false, AcknowledgeMode.Auto))
    {
    using (IMessageConsumer consumer = session.CreateDurableSubscriber(destination, props.DestinationName))
    {
    // start the connection
    connection.Start();
    while (messageCount < messageTotal)
    {
    bodyMessage = "";
    try
    {
    // receive a message
    [b] IMessage msg = consumer.Receive();[/b]
    
    if (msg is IMapMessage)
    {
    //Console.WriteLine("Message Body: " + ((ITextMessage)message).Text);
    
    }
    else if (msg is ITextMessage)
    {
    Console.WriteLine("Message Body: " + ((ITextMessage)msg).Text);
    }
    else if (msg is IBytesMessage)
    {
    //Console.WriteLine("Message Body: " + ((ITextMessage)message).Text);
    }
    }
    catch (Exception ex)
    {
    //HelperLog.Logger.ErrorFormat("Error getting message from step. Message detail {0}", ex);
    }
    // increment the counter
    messageCount++;
    if (!string.IsNullOrEmpty(bodyMessage))
    {
    Process(bodyMessage);
    }
    }
    
    } // close the consumer
    
    } // close the session
    
    } // close the connection
    

    #broker
    #Universal-Messaging-Broker
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/25/17 08:06 AM

    Hi,

    in your code sample I cannot identify where bodyMessage is populated.
    It is only initialzed as empty string.

    Regards,
    Holger


    #webMethods
    #broker
    #Integration-Server-and-ESB
    #Universal-Messaging-Broker


  • 5.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/25/17 09:05 AM

    The bodymessage is populated in the receive method. This method returned a BytesMessage

    IMessage msg = consumer.Receive();


    #broker
    #webMethods
    #Universal-Messaging-Broker
    #Integration-Server-and-ESB


  • 6.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/25/17 09:23 AM

    Hi Rui,

    I am a Java Developer, not a C# Developer.

    But from my understanding the isNullOrEmpty is always returning true as bodyMessage only contains a String of lentgh 0 (emptyString).
    Processing an empty String does not make sense to me.

    Regards,
    Holger


    #Universal-Messaging-Broker
    #broker
    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/25/17 11:16 AM

    Hi, You are correct, there no sense, processing message if it is empty. My mistake and, i already fix it in sample above. But the problem is before, when i receive the message


    #webMethods
    #Universal-Messaging-Broker
    #broker
    #Integration-Server-and-ESB


  • 8.  RE: C# API Subscribe Using webMethods Broker How To Read BytesMessage

    Posted 01/25/17 01:52 PM

    Hi Rui,

    I am still wondering where bodyMessage is populated as I only see its initialization with “”.

    bodyMessage is of type String, right?

    Then you will have to extract its value from the correct element out of the Message Object.
    There should be some methods to extract the data from the message.

    Regards,
    Holger


    #Integration-Server-and-ESB
    #Universal-Messaging-Broker
    #broker
    #webMethods