apache karaf_Apache Karaf遇到Apache HBase
apache karaf
介紹
Apache HBase是一個以Google Bigtable為藍本的開源,分布式,版本化,面向列的商店。 如果您是普通讀者,那么您可能已經知道Apache Karaf是什么,但是對于那些不是的讀者:Apache Karaf是一個OSGi運行時,可以在任何OSGi框架之上運行,并為您提供一系列服務,強大的配置概念,可擴展的外殼等等。
由于Apache HBase 尚未準備好OSGi,因此開發OSGi應用程序的人通常很難理解如何在OSGi中使用HBase。
這篇文章解釋了如何構建使用HBase的OSGi應用程序。 請注意,這篇文章不是關于在OSGi中運行HBase的部分,而是重點介紹如何在OSGi中使用客戶端api。 與往常一樣,我將重點介紹基于Karaf的容器,例如Apache ServiceMix , Fuse ESB等,但本文中的大多數內容通常適用于所有OSGi運行時。
HBase和OSGi
讓我們仔細看一下HBase,并解釋一下HBase與OSGi的關系。
壞消息
- HBase不提供OSGi元數據,這意味著您需要自己包裝HBase或為HBase找到第三方捆綁包。
- HBase作為單個jar傳入。
- 使用Hadoop配置。
第一點很簡單。 乍一看,第二點似乎并不是什么壞消息,但是如果您稍加思考,您就會意識到,當所有東西都放在一個罐子里時,它們并不是完全模塊化的。 例如,客戶端api位于同一個jar中,具有avro和thrift接口,即使您不需要它們,它們仍將在那里。 因此,該jar中包含的東西對于您的用例可能完全沒有用。
請注意,單個jar語句不引用諸如Hadoop或Zookeeper之類的依賴項。
作為HBase的事實取決于Hadoop配置加載機制,這也是個壞消息,因為在OSGi中運行時,某些版本的Hadoop有點發癢。
好消息
- HBase內沒有類加載怪物,因此當您嘗試在OSGi內使用客戶端api時不會被咬住。
挑戰
因此,存在兩種類型的挑戰,第一種挑戰是為HBase找到或創建一個捆綁包,該捆綁包將具有對您的用例有意義的要求。 第二個是在OSGi中加載hbase客戶端配置。
尋找HBase的捆綁包
據我所知, Apache ServiceMix Bundles提供了用于HBase的捆綁軟件 。 但是,當前提供的捆綁軟件在所需軟件包方面的需求比實際需要的要多(請參閱壞消息,第二點)。 提供具有更明智要求的捆綁包目前仍在進行中,希望將很快發布。
在此端口中,我將使用Pax Url Wrap Protocol 。 包裝協議將為任何jar動態創建OSGi元數據。 此外,所有包導入都將標記為可選,因此您不必處理不必要的要求。 這可以幫助您入門,但是不建議在生產環境中使用。 因此,您可以在POC中使用它,但是當它需要投入生產時,最好使用適當的捆綁包。
為HBase創建Karaf功能描述符
經過試驗后,我發現可以通過安裝以下功能描述符中列出的捆綁軟件在Karaf中使用HBase:
<feature name="hbase" version="0.90.5" resolver="(obr)" start-level="50"> <feature>war</feature> <bundle dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxws-api-2.2/1.9.0</bundle> <bundle dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.saaj-api-1.3/1.9.0</bundle> <bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle> <bundle dependency="true">mvn:javax.mail/mail/1.4.5</bundle> <bundle dependency="true">mvn:commons-codec/commons-codec/1.6</bundle> <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-beanutils/1.8.3_1</bundle> <bundle dependency="true">mvn:commons-collections/commons-collections/3.2.1</bundle> <bundle dependency="true">mvn:commons-digester/commons-digester/2.1</bundle> <bundle dependency="true">mvn:commons-jxpath/commons-jxpath/1.3</bundle> <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jdom/1.1_4</bundle> <bundle dependency="true">mvn:commons-lang/commons-lang/2.6</bundle> <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.7.0_6</bundle> <bundle dependency="true">mvn:commons-configuration/commons-configuration/1.6</bundle> <bundle dependency="true">mvn:commons-daemon/commons-daemon/1.0.5</bundle> <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient/3.1_7</bundle> <bundle dependency="true">mvn:org.apache.commons/commons-math/2.2</bundle> <bundle dependency="true">mvn:commons-net/commons-net/3.1</bundle> <bundle dependency="true">mvn:org.codehaus.jackson/jackson-core-asl/1.9.7</bundle> <bundle dependency="true">mvn:org.codehaus.jackson/jackson-mapper-asl/1.9.7</bundle> <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jetty/6.1.26_4</bundle> <bundle dependency="true">mvn:org.apache.zookeeper/zookeeper/3.3.5</bundle><bundle> mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.hadoop-core/1.0.0_2</bundle> <bundle>wrap:mvn:org.apache.hbase/hbase/0.90.5</bundle> </feature>實際上,此功能描述符與最新版本的Apache Camel提供的功能描述符幾乎相同。 區別之一是使用的Apache Hadoop版本。 在此示例中,我傾向于使用稍低版本的Apache Hadoop,它在OSGi中的表現似乎更好。
在OSGi中創建HBase客戶端配置
本節中描述的內容可能會有所不同,具體取決于您使用的Hadoop jar版本。 我將嘗試提供涵蓋所有情況的一般解決方案。
通常,在配置hbase客戶端時,您只需要在類路徑中保留一個hbase-site.xml。 在OSGi內部,這并不總是足夠的。 某些版本的hadoop將設法獲取該文件,而另一些則不會。 在許多情況下,hbase會抱怨當前版本與hbase-defatult.xml中的版本不匹配。
一種解決方法是將hbase.defaults.for.version設置為與您的HBase版本匹配:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration><property><name>hbase.zookeeper.quorum</name><value>localhost</value></property><property><name>hbase.zookeeper.property.clientPort</name><value>2181</value></property><property><name>hbase.defaults.for.version</name><value>${hbase.version}</value></property> </configuration>在大多數情況下,可以節省您的一種方法是在創建配置對象之前,將hbase bundle classloader設置為線程上下文類加載器。
Thread.currentThread().setContextClassLoader(HBaseConfiguration.class.getClassLoader());我之所以提出這個建議,是因為hbase將利用線程上下文類加載器來加載資源(hbase-default.xml和hbase-site.xml)。 設置TCCL將允許您加載默認值,并在以后覆蓋它們。
下面的代碼片段顯示了如何設置TCCL以便直接從hbase捆綁包中加載默認值。
ClassLoader ocl = Thread.currentThread().getContextClassLoader();try {Thread.currentThread().setContextClassLoader(HBaseConfiguration.class.getClassLoader());Configuration conf = HBaseConfiguration.create();} finally {Thread.currentThread().setContextClassLoader(ocl); }請注意,采用這種方法時,您無需在軟件包中包含hbase-site.xml。 您將需要以編程方式設置配置。
另請注意,在某些情況下,如果HBase找不到正確的類加載器,則HBase內部類將重新創建配置,這可能會導致您遇到問題。
思想
HBase與幾乎所有不提供對OSGi的即開即用支持的庫一樣。 如果您了解類加載的基礎知識,則可以使其正常工作。 當然,無論您是否使用OSGi,了解類裝入器都是遲早要使用的。
在接下來的幾周中,我打算使用OSGi中全新的camel-hbase組件乘坐HBase騎在駱駝的背面,敬請期待 。
編輯:原始帖子已被編輯,因為其中包含一個摘要,我發現最好避免該摘要(將HBase配置共享為OSGi服務)。
翻譯自: https://www.javacodegeeks.com/2013/11/apache-karaf-meets-apache-hbase.html
apache karaf
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的apache karaf_Apache Karaf遇到Apache HBase的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 两台电脑共享宽带(两台电脑局域网共享)
- 下一篇: 8.4版本文森特最新符文(文森特符文出装