当前位置: 首页>>代码示例>>Java>>正文


Java ConsumerCallback类代码示例

本文整理汇总了Java中org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback的典型用法代码示例。如果您正苦于以下问题:Java ConsumerCallback类的具体用法?Java ConsumerCallback怎么用?Java ConsumerCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConsumerCallback类属于org.apache.nifi.jms.processors.JMSConsumer包,在下文中一共展示了ConsumerCallback类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateFailOnUnsupportedMessageTypeOverJNDI

import org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback; //导入依赖的package包/类
public void validateFailOnUnsupportedMessageTypeOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:24,代码来源:JMSPublisherConsumerTest.java

示例2: validateFailOnUnsupportedMessageType

import org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback; //导入依赖的package包/类
/**
 * At the moment the only two supported message types are TextMessage and
 * BytesMessage which is sufficient for the type if JMS use cases NiFi is
 * used. The may change to the point where all message types are supported
 * at which point this test will no be longer required.
 */
@Test(expected = IllegalStateException.class)
public void validateFailOnUnsupportedMessageType() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:31,代码来源:JMSPublisherConsumerTest.java

示例3: rendezvousWithJms

import org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback; //导入依赖的package包/类
/**
 * Will construct a {@link FlowFile} containing the body of the consumed JMS
 * message (if {@link GetResponse} returned by {@link JMSConsumer} is not
 * null) and JMS properties that came with message which are added to a
 * {@link FlowFile} as attributes, transferring {@link FlowFile} to
 * 'success' {@link Relationship}.
 */
@Override
protected void rendezvousWithJms(final ProcessContext context, final ProcessSession processSession) throws ProcessException {
    final String destinationName = context.getProperty(DESTINATION).evaluateAttributeExpressions().getValue();
    this.targetResource.consume(destinationName, new ConsumerCallback(){
        @Override
        public void accept(final JMSResponse response) {
            if (response != null){
                FlowFile flowFile = processSession.create();
                flowFile = processSession.write(flowFile, new OutputStreamCallback() {
                    @Override
                    public void process(final OutputStream out) throws IOException {
                        out.write(response.getMessageBody());
                    }
                });
                Map<String, Object> jmsHeaders = response.getMessageHeaders();
                Map<String, Object> jmsProperties = Collections.<String, Object>unmodifiableMap(response.getMessageProperties());
                flowFile = ConsumeJMS.this.updateFlowFileAttributesWithJMSAttributes(jmsHeaders, flowFile, processSession);
                flowFile = ConsumeJMS.this.updateFlowFileAttributesWithJMSAttributes(jmsProperties, flowFile, processSession);
                flowFile = processSession.putAttribute(flowFile, JMS_SOURCE_DESTINATION_NAME, destinationName);
                processSession.getProvenanceReporter().receive(flowFile, destinationName);
                processSession.transfer(flowFile, REL_SUCCESS);
                processSession.commit();
            } else {
                context.yield();
            }
        }
    });
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:36,代码来源:ConsumeJMS.java

示例4: validateConsumeWithCustomHeadersAndProperties

import org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback; //导入依赖的package包/类
@Test
public void validateConsumeWithCustomHeadersAndProperties() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage("hello from the other side");
            message.setStringProperty("foo", "foo");
            message.setBooleanProperty("bar", false);
            message.setJMSReplyTo(session.createQueue("fooQueue"));
            return message;
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    final AtomicBoolean callbackInvoked = new AtomicBoolean();
    consumer.consume(destinationName, new ConsumerCallback() {
        @Override
        public void accept(JMSResponse response) {
            callbackInvoked.set(true);
            assertEquals("hello from the other side", new String(response.getMessageBody()));
            assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
            assertEquals("foo", response.getMessageProperties().get("foo"));
            assertEquals("false", response.getMessageProperties().get("bar"));
        }
    });
    assertTrue(callbackInvoked.get());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:33,代码来源:JMSPublisherConsumerTest.java

示例5: validateConsumeWithCustomHeadersAndPropertiesOverJNDI

import org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback; //导入依赖的package包/类
@Test
public void validateConsumeWithCustomHeadersAndPropertiesOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage("hello from the other side");
            message.setStringProperty("foo", "foo");
            message.setBooleanProperty("bar", false);
            message.setJMSReplyTo(session.createQueue("fooQueue"));
            return message;
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    final AtomicBoolean callbackInvoked = new AtomicBoolean();
    consumer.consume(destinationName, new ConsumerCallback() {
        @Override
        public void accept(JMSResponse response) {
            callbackInvoked.set(true);
            assertEquals("hello from the other side", new String(response.getMessageBody()));
            assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
            assertEquals("foo", response.getMessageProperties().get("foo"));
            assertEquals("false", response.getMessageProperties().get("bar"));
        }
    });
    assertTrue(callbackInvoked.get());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:33,代码来源:JMSPublisherConsumerTest.java


注:本文中的org.apache.nifi.jms.processors.JMSConsumer.ConsumerCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。