001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.example.guice.jms;
018
019 import com.google.inject.Injector;
020 import com.google.inject.Provides;
021 import com.google.inject.name.Named;
022 import org.apache.activemq.ActiveMQConnectionFactory;
023 import org.apache.camel.component.jms.JmsComponent;
024 import org.apache.camel.guice.CamelModuleWithMatchingRoutes;
025 import org.guiceyfruit.jndi.JndiBind;
026
027 /**
028 * Configures the CamelContext, RouteBuilder, Component and Endpoint instances using
029 * Guice
030 *
031 * @version $Revision: 885196 $
032 */
033 public class MyModule extends CamelModuleWithMatchingRoutes {
034
035 @Override
036 protected void configure() {
037 super.configure();
038
039 // lets add in any RouteBuilder instances we want to use
040 bind(MyRouteBuilder.class);
041 bind(Printer.class);
042 }
043
044 /**
045 * Lets configure the JMS component, parameterizing some properties from the
046 * jndi.properties file
047 */
048 @Provides
049 @JndiBind("jms")
050 JmsComponent jms(@Named("activemq.brokerURL") String brokerUrl) {
051 return JmsComponent.jmsComponent(new ActiveMQConnectionFactory(brokerUrl));
052 }
053
054 @Provides
055 @JndiBind("myBean")
056 SomeBean someBean(Injector injector) {
057 return injector.getInstance(SomeBean.class);
058 }
059 }