【问题标题】:ESB Fuse module waiting on dependency - Grace PeriodESB Fuse 模块等待依赖 - 宽限期
【发布时间】:2013-06-29 16:22:32
【问题描述】:

我有一个基本的 ESB Fuse 测试项目,其中包含以下模块:

简单数据源 简单模型 简单的服务

datasource通过blueprint配置,datasource附加到jndi:

<?xml version="1.0" encoding="UTF-8"?>

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<bean id="simpleDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=xyz))(ADDRESS=(PROTOCOL=TCP)(HOST=xx.xx.xx.xx)(PORT=1521)))" />
    <property name="username" value="username" />
    <property name="password" value="password" />       
</bean>

<!--bean id="simpleDataSource" class="oracle.jdbc.driver.OracleDriver">     
    <property name="URL" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=devd))(ADDRESS=(PROTOCOL=TCP)(HOST=10.75.192.195)(PORT=1521)))"/>
    <property name="username" value="username" />
    <property name="password" value="password" />       
</bean-->

<service ref="simpleDataSource" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/simpleDataSource" />
    </service-properties>
</service>

模型在 persistence.xml 文件中定义了一个持久化单元,并通过 jndi 引用数据源(注意这里定义的长短 jndi 查找,我都尝试过):

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.0">

<persistence-unit name="simple-service-persistence-unit" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <!--jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/simpleDataSource)</jta-data-source-->
    <jta-data-source>osgi.jndi.service.name=jdbc/simpleDataSource</jta-data-source>
    <!-- list of the persistance classes -->
    <class>com.model.SimpleRow</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>

SimpleRow 类使用 JPA 注释:

package com.model;

导入 javax.persistence.Column; 导入 javax.persistence.Entity; 导入 javax.persistence.Table;

@实体 @Table(name = "简单") 公共类 SimpleRow {

@Column(name = "simple_id")
private Long simpleId;

@Column(name = "simple_text", length =100)
private String simpleText;

public Long getSimpleId() {
    return simpleId;
}

public void setSimpleId(Long simpleId) {
    this.simpleId = simpleId;
}

public String getSimpleText() {
    return simpleText;
}

public void setSimpleText(String simpleText) {
    this.simpleText = simpleText;
}

}

然后我尝试将 EntityManager 注入服务,再次使用蓝图和对 simple-service-persistence-unit 的引用:

<?xml version="1.0" encoding="UTF-8"?>

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/xmlns/jpa/v1.1.0http://aries.apache.org/schemas/jpa/jpa_110.xsd">

<bean id="simpleService" class="com.service.SimpleServiceImpl">
    <jpa:context property="entityManager" unitname="simple-service-persistence-unit" />
    <tx:transaction method="*" value="Required" />
</bean>

<service ref="simpleService" interface="com.service.SimpleService" />

现在,当我将这些模块安装到 fuse OSGi 容器中时,simple-datasource 和 simple-module 似乎都已正确安装。列出这些模块给出:

[ 274] [Active     ] [            ] [       ] [   60] Simple Model (1.0.0)
[ 275] [Active     ] [Created     ] [       ] [   60] Simple Datasource (1.0.0)

我创建了一个使用注入 DataSource 的测试 jdbc 模块,这证实了 DataSource 工作正常,例如

public class DbExample {
DataSource dataSource;

public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
}

public void test() throws Exception {
    Connection con = dataSource.getConnection();
    Statement stmt = null;
    DatabaseMetaData dbMeta = con.getMetaData();
    ....
 }

现在,当我尝试启动 simple-service 时,它​​会进入宽限期状态,并将以下消息打印到日志文件中:

2013-07-02 11:05:33,772 | INFO  | e-1.0.0-thread-1 | BlueprintContainerImpl           | ?                                   ? | 8 - org.apache.aries.blueprint.core - 1.0.1.fuse-71-047 | Bundle simple-service is waiting for dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=simple-service-persistence-unit))(objectClass=javax.persistence.EntityManagerFactory))]

列出模块状态表明它处于宽限期状态:

[ 277] [Active     ] [GracePeriod ] [       ] [   60] Simple Service Bundle (1.0.0)

它最终会超时并进入失败状态。

现在我最初的想法是它可能是一个损坏的数据源,但 jdbc 模块证明它工作正常。我随后的想法是 jndi 查找工作不正常,尽管我不确定如何检查。有什么方法可以查看 jndi 注册表吗?欢迎任何其他建议。

【问题讨论】:

  • ls 275 显示什么?

标签: osgi datasource fuseesb


【解决方案1】:

您的捆绑包正在等待服务显示,这可能是一个问题,因为您引用的服务不可用(打开 DEBUG 登录,您将在日志中看到详细信息)或什么有时会发生(取决于 Karaf/Aries 的底层版本)您需要切换蓝图以使用同步部署,因为有时等待的捆绑包无法捕获稍后启动的服务。为此,您需要翻转 etc/config.properties 文件中的 org.apache.aries.blueprint.synchronous=true

【讨论】:

  • 梳理日志后发现simple-service模块正在等待事务功能。这只是作为一条 INFO 消息在日志中进一步报告,因此最初并没有引起我的注意。
猜你喜欢
  • 1970-01-01
  • 2019-04-22
  • 1970-01-01
  • 1970-01-01
  • 2016-01-14
  • 1970-01-01
  • 2023-03-29
  • 2020-11-18
  • 2018-08-06
相关资源
最近更新 更多