All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nstream.adapter.jms.JmsIngestingPatch Maven / Gradle / Ivy

There is a newer version: 4.15.23
Show newest version
// Copyright 2015-2024 Nstream, inc.
//
// Licensed under the Redis Source Available License 2.0 (RSALv2) Agreement;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://redis.com/legal/rsalv2-agreement/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nstream.adapter.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import nstream.adapter.common.AdapterUtils;
import nstream.adapter.common.ext.JmsIngressSettings;
import nstream.adapter.common.schedule.DeferrableException;
import swim.structure.Value;

/**
 * A concrete but extendable implementation of {@link JmsIngestingAgent}
 * that uses configuration to structure and relay the received
 * JMS {@link Message}.
 *
 * @see JmsIngestingAgent
 * @see JmsIngressSettings
 */
public class JmsIngestingPatch extends JmsIngestingAgent {

  public JmsIngestingPatch() {
  }

  @Override
  protected void ingest(Message unstructured) throws DeferrableException {
    final Value v = assembleIngest(unstructured);
    ingest(v);
  }

  /**
   * Structure the received {@link Message} into a {@link Value} as
   * defined by configuration.
   *
   * @param unstructured the received message
   * @return message in {@link Value} form
   */
  protected Value assembleIngest(Message unstructured) throws DeferrableException {
    try {
      return JmsAdapterUtils.assembleIngest(unstructured, this.ingressSettings);
    } catch (JMSException jmsException) {
      throw new DeferrableException(nodeUri() + ": exception while assembling message", jmsException);
    }
  }

  /**
   * Ingest a message after it has been structured into a {@link Value} object.
   * Will relay the message as configured by the relay schema in the settings.
   *
   * @param messageStructure the received message structured into a {@link Value}
   * @throws DeferrableException an exception that will be handled without aborting ingestion
   */
  protected void ingest(Value messageStructure) throws DeferrableException {
    AdapterUtils.ingressDslRelay(this.ingressSettings.relaySchema(),
        agentContext(), messageStructure);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy