{"record":{"id":"8a601d120583c6ad","repo":"apache/beam","slug":"error-creating-textmessage","errorCode":null,"errorMessage":"Error creating TextMessage","messagePattern":"Error creating TextMessage","errorType":"exception","errorClass":"JmsIOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/TextMessageMapper.java","lineNumber":39,"sourceCode":"import javax.jms.Message;\nimport javax.jms.Session;\nimport javax.jms.TextMessage;\nimport org.apache.beam.sdk.transforms.SerializableBiFunction;\n\n/**\n * The TextMessageMapper takes a {@link String} value, a {@link javax.jms.Session} and returns a\n * {@link javax.jms.TextMessage}.\n */\npublic class TextMessageMapper implements SerializableBiFunction<String, Session, Message> {\n\n  @Override\n  public Message apply(String value, Session session) {\n    try {\n      TextMessage msg = session.createTextMessage();\n      msg.setText(value);\n      return msg;\n    } catch (JMSException e) {\n      throw new JmsIOException(\"Error creating TextMessage\", e);\n    }\n  }\n}\n","sourceCodeStart":21,"sourceCodeEnd":43,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/TextMessageMapper.java#L21-L43","documentation":"TextMessageMapper.apply() creates a JMS TextMessage from a String value via session.createTextMessage() and setText(); a JMSException during this is rethrown as a JmsIOException with message \"Error creating TextMessage\". This converts the checked JMSException into an unchecked error suitable for Beam pipelines.","triggerScenarios":"Session is closed/broken when the mapper runs (session.createTextMessage() throws), or msg.setText() fails due to an invalid/broken session or message state.","commonSituations":"Broker connection dropped mid-pipeline so sessions are invalid; long-lived producers hitting idle connection timeouts; broker restarts.","solutions":["Check the chained JMSException cause for session/connection state issues.","Verify broker connectivity and reconnect/retry configuration for the JMS write transform.","Ensure the producer's session is recreated on failure (JmsIO handles this internally; don't share sessions across threads)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { Message m = textMessageMapper.apply(value, session); }\ncatch (JmsIOException e) {\n  if (e.getCause() instanceof JMSException) {\n    // session likely closed; recreate session and retry\n  }\n}","preventionTips":["Don't share JMS sessions across threads.","Enable broker reconnect/failover settings (e.g. failover:// transport for ActiveMQ).","Keep producer sessions short-lived or recreate on failure."],"tags":["jms","message","session"],"backgroundTag":"api-error-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}