`
wangleifire
  • 浏览: 500777 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

camel入门 xmpp tcp 配置 之XMPPReceiver

阅读更多

 

这个是服务器

 

package testxmpp;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Producer;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.xmpp.XmppEndpoint;
import org.apache.camel.component.xmpp.XmppExchange;
import org.apache.camel.component.xmpp.XmppMessage;
import org.apache.camel.component.xmpp.XmppPrivateChatProducer;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.cxf.common.logging.Log4jLogger;
import org.apache.log4j.Logger;
import org.jivesoftware.smack.XMPPConnection;

import back.SendMessage;


/**
 * 上面例子的第一行创建一个一个RouteBuilder的匿名类的实例,这个匿名类需要实现 configure()方法。
 * camelContext.addRoutes(RouterBuilder builder)
 * 方法中调用了builder.setContext(this)方法,
 * 这样RouteBuilder对象就获得了与之对应的CamelContext的,然后调用builder.configure()方法。
 * 在configure方法中,可以调用例如 from(), filter(), choice(), when(),isEqualTo(),
 * otherwise()以及to()方法。 RouteBuilder.from(String uri)
 * 方法会调用与之对应的CamelContext的getEndpoint(uri)方法来获得指定的Endpoint,
 * 并用一个FromBuilder包装这个Endpoint。这样 FromBuilder.filter(Predicate predicate)
 * 方法就会创建一个在header("foo").isEqualTo("bar")这个表达式基础创建的Predicate(所谓的条件) 创建一个
 * FilterProcessor对象。就这样,通过定义这些操作我们逐渐构建出了一个Route对象
 * (使用RouterBuilder进行包装的)并且将这个Route对象添加进了与RouteBuilder所关联的CamelContext中。
 *
 */

public class XmppReceiver {

    public static void main(String[] s) {
       
        String host = "192.168.1.20" ;
        String port = "5201" ;
        try {
            CamelContext context = new DefaultCamelContext();
           
           
            // 增加路由的接点,可以是一个URL也可以是file://test这样一个中间接点,用于转到下个路由
            final Endpoint endpoint = context.getEndpoint("mina:tcp://"+host+":"+port);
            final XmppEndpoint xmppendpoint = new XmppEndpoint("xmpp://localhost:5200") ;
           
            context.addRoutes(new RouteBuilder() {
                public void configure() {
                    // from("queue:a").filter(header("foo").isEqualTo("bar")).to("queue:b");
                    from(endpoint).process(new Processor() {
                                public void process(Exchange e)
                                        throws Exception {

                                    Logger.getLogger(XmppReceiver.class).info("success!"+ header("foo").isEqualTo("bar"));

                                    e.getOut().setBody(e.getIn().getBody());
                                }
                            }).to("direct:start");

                    //选择的方式,如果被其中一个when选中,就不再往下走了。
                    from("direct:start").choice()
                            .when(new MessageFilter(body())).to("direct:a")
                            .when(new MessageFilter(body())).to("direct:b")
                            .otherwise().to("direct:c") ;
                   
                    from("direct:a").process(new Processor() {
                        public void process(Exchange arg0) throws Exception {
                            Logger.getLogger(XmppReceiver.class).info("To direct:a");
                            }
                    });

                    from("direct:b").process(new Processor() {
                        public void process(Exchange arg0) throws Exception {
                            Logger.getLogger(XmppReceiver.class).info("To direct:b");
                            }
                    });
                    from("direct:c").process(new Processor() {
                        public void process(Exchange arg0) throws Exception {
                            Logger.getLogger(XmppReceiver.class).info("To direct:c");
                        }
                    });
                }
            });

            context.start();
            Logger.getLogger(XmppReceiver.class).info("success!");
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
}

分享到:
评论

相关推荐

    spring-boot-camel-config:Spring Boot Camel配置快速入门

    使用ConfigMap和Secrets的Spring-Boot Camel快速入门本快速入门演示了如何使用Kubernetes ConfigMap和Secrets配置Spring-Boot应用程序。 路由会生成示例消息,这些示例消息将传递到通过src/main/resources/...

    针对Java开发者的ApacheCamel入门指南

    在这篇文章中,我将提供一个Java语言(非Groovy)的ApacheCamel入门演示。首先创建一个Maven项目的pom.xml。在这里我们只用到了camel-core.jar包,实际上它提供了许多你可能用到的实用组件。出于日志记录的目的,我...

    Camel in action(camel实战)

    Apache Camel is a Java framework that lets you implement the standard enterprise integration patterns in a few lines of code. With a concise but sophisticated DSL you snap integration logic into your ...

    camel配置TIBCO-topic

    camel配置TIBCO-topic配置文件详解

    [Camel实战].(Camel.in.Action).Claus.Ibsen&Jonathan;.Anstey.文字版

    中文名: Camel 实战 原名: Camel in Action 作者: Claus Ibsen Jonathan Anstey 资源格式: PDF 版本: 英文文字版/更新源代码 出版社: Manning书号: 9781935182368发行时间: 2010年12月 地区: 美国 语言: 英文 简介: ...

    ApacheCamel快速入门(中)

    接上文EndpointDirect用于在两个编排好的路由间实现Exchange消息的连接,上一个路由中由最后一个元素处理完的Exchange对象,将被发送至由Direct连接的下一个路由起始位置(http://camel.apache.org/direct.html)。...

    Camel_Camel3Camel6函数_

    Camel3 Camel6函数等matlab源代码

    ApacheCamel-JDBC

    ApacheCamel-JDBC Apache Camel JDBC组件 代码样例Demo

    ApacheCamel快速入门(上)

    在这个专题中,我们介绍了相当数量技术组件:Flume、Kafka、ActiveMQ、Rabbitmq、Zookeeper、Thrift、Netty、DUBBO等等,还包括本文要进行介绍的ApacheCamel。有的技术组件讲得比较深入,有的技术组件则是点到为止。...

    apache-camel-demo

    Apache Camel是一个基于规则路由和中介引擎,提供企业集成模式的Java对象(POJO)的实现,通过应用程序接口(或称为陈述式的Java领域特定语言(DSL))来配置路由和中介的规则。领域特定语言意味着Apache Camel支持你...

    Camel in Action.zip

    Apache Camel 作为集成项目的利器,针对应用集成场景的抽象出了一套消息交互模型,通过组件的方式进行第三方系统的接入,目前Apache Camel已经提供了300多种组件能够接入HTTP,JMS,TCP,WS-*,WebSocket 等多种传输...

    ApacheCamel快速入门(下)

    接上文动态循环路由的特点是开发人员可以通过条件表达式等方式,动态决定下一个路由位置。在下一路由位置处理完成后Exchange将被重新返回到路由判断点,并由动态循环路由再次做出新路径的判断。...

    spring-boot-camel-xml:一个快速入门,展示了如何将Spring Boot和camel与XML DSL以及Kubernetes或OpenShift一起使用

    本示例演示了如何通过Spring XML配置文件在Spring Boot中配置骆驼路线。 该应用程序利用Spring 批注通过类路径上的src / main / resources / spring / camel-context.xml文件加载Camel Context定义。 重要的 该...

    Camel服务集成,服务编排操作文档

    Camel服务集成,服务编排操作文档

    Apache Camel中文开发使用指南.zip

    Apache Camel 开发使用指南中文版

    ServiceMix Bundle Camel ActiveMQ环境搭建入门实例Demo

    本书适合入门学习,所有例子都有源码 1.Servicemix环境安装和配置 2.Eclipse开发环境安装搭建 3.用Bundle对应用组件模块化 4.Camel的应用和例子 Bundle之间的消息传递, Errorhandling 负载均衡 。。。。。。 5....

    Camel in Action ch1

    1: Meet Camel - FREE 2: Routing with Camel - AVAILABLE Part 2 Core Camel 3: Transforming Data with Camel - AVAILABLE 4: Using Beans with Camel - AVAILABLE 5: Error Handling - AVAILABLE 6:...

    Camel实战中文版第四章.pdf

    Camel In Action一书第四章的中文版。

    大众点评开源软负载管理中间件 Camel.zip

    Camel 是大众点评开发的软负载一体解决方案,承担了F5硬负载层后的软负载工作。Camel已成为大众点评网络流量中必不可缺的一层。 关于Camel的部署及使用,请参考Camel in Action: 国内 国外 Camel在大众点评的...

Global site tag (gtag.js) - Google Analytics