jms_set_message_property

Sets a JMS header or property for the next message to be sent, or uses a JMS header or property to filter received messages.

Web Services Functions (SOAP, WEB_SERVICE, Silverlight)
int jms_set_message_property( const char * StepName, const char * name, const char * value);

This function returns LR_PASS (0) on success or LR_FAIL (1) on failure. Note that LR_PASS and LR_FAIL generally indicate whether the function call completed without an exception, and not that the test step succeeded.

All input string arguments (char type) except the step name can be parameterized using standard parameterization.

StepName The name of the step, as it appears in the test tree. Any text can be used.
name The name of the header or property.
value The value of the header or property.

jms_set_message_property sets a JMS header or property for the next message to be sent, or uses a JMS header or property to filter received messages.

For Peer-to-Peer messages received using queues, the filter applies to the next message received. To set the filter for the next message, insert jms_set_message_property before jms_receive_message_queue or jms_send_receive_message_queue. After the next message, all messages are received.

For Publish-Subscribe messages received using topics, the filter applies to all messages received for the subscription. To set the filter for an entire subscription, insert jms_set_message_property before jms_subscribe_topic.

The following JMS headers are supported:

  • JMSCorrelationID

  • JMSDeliveryMode

  • JMSExpiration

  • JMSMessageID

  • JMSPriority

  • JMSRedelivered

  • JMSTimestamp

  • JMSType

A property with any other name is added as a JMS property.

The contentType property determines the sent message type.

Specify the JMSSelector property to:

  • Construct a message.

  • To set several properties, insert multiple jms_set_message_property calls in the script before sending or publishing a message.

  • Set a selector (filter) for received messages.

  • Insert one jms_set_message_property call in the script before subscribing to a topic or receiving a message from queue. Set the value of the JMSSelector property to a string that contains a conditional expression, with full Boolean logic. For more information on the syntax for defining selectors, see the Oracle Interface Message documentation.

Example

This example shows using jms_set_message_property to set up for queuing a message.

long t=1;
char *chr;
t=time(&t);
t = t + 100000;
chr = (char*)malloc(20, sizeof(char));
sprintf(chr,"%d",t);
jms_set_message_property("JMSExpiration","JMSExpiration", chr);
jms_set_message_property("JMSMessageID","JMSMessageID", "-JMSMessageID-");
jms_set_message_property("JMSPriority","JMSPriority", "9"); //0-9, 4 is default
jms_set_message_property("JMSRedelivered","JMSRedelivered", "true"); 
jms_send_message_queue("sending message 1","RecordedBuffer1", "TestJMSQueue");

This example shows setting the JMSCorrelationID property, and then sending/receiving a message.
jms_set_message_property("step0: set the JMSCorrelationID", 
    "JMSCorrelationID", 
    "VuserID-{VuserID}");

jms_send_receive_message_queue("step1: send and receive message", 
    "Test Message", 
    "weblogic.jms.inqueue", 
    "weblogic.jms.outqueue");

lr_message(lr_eval_string("{JMS_message}"));

This example shows how to set a custom selector for a subscription. Any message whose flag value is set to "no" is received on a specific topic. 
jms_set_message_property("selector_step", "JMSSelector", "flag = \'no\'");
jms_subscribe_topic("subscribe_step", "subscription_1", "testTopic");
jms_publish_message_topic("publish_step", "message to publish", "testTopic");
jms_receive_message_topic("receive_step", "subscription_1", "testTopic");
lr_output_message(lr_eval_string("message : \n{JMS_message}\n"));
This example shows how to filter messages received for a subscription by correlation ID. Only messages whose correlation ID is 4566636 are received.
/* This call sets the filter for the all messages received for this subscription. */
jms_set_message_property("prop","JMSCorrelationID","4566636");
jms_subscribe_topic("subcribe_step", "subscription_1", "testTopic"); 
/* This call sets the correlation ID for the next message to be sent. */
jms_set_message_property("prop","JMSCorrelationID","123");
jms_publish_message_topic("publish_step", "This message matches Correlation ID 123", "testTopic");
/* This message is not received because the correlation ID does not match the filter. */
jms_receive_message_topic("receive_step", "subscription_1", "testTopic"); 
lr_output_message(lr_eval_string("message: {JMS_message}\n"));
/* This call sets the correlation ID for the next message to be sent. */
jms_set_message_property("prop","JMSCorrelationID","4566636");
jms_publish_message_topic("publish_step", "This message matches Correlation ID 4566636", "testTopic"); 
/* This message is received because the correlation ID matches the filter. */
jms_receive_message_topic("receive_step", "subscription_1", "testTopic"); 
lr_output_message(lr_eval_string("message: {JMS_message}\n"));