我以Spring Batch Talk 为参考,参与了Spring Batch Admin示例。这个例子完全符合我的要求。使用Rabbit服务器,我建立了主服务器和从服务器之间的通信。但是,我怎么知道哪个分区在master中运行,哪个分区在slave中运行。有没有机会从Spring Batch Admin UI查看它。
答案 0 :(得分:0)
在ColumnRangePartitioner
中进行分区时,我又向ExecutionContext添加了一个值partitionId。
value.putLong("minValue", start);
value.putLong("maxValue", end);
value.putLong("partitionId", number);
我在TARGET中添加了一个名为partitionInfo的新列,它存储了在哪个分区中扫描了哪个端口的详细信息。在读取端口时,我已经明确添加了值。
<bean id="targetItemReader" class="org.springframework.batch.item.database.JdbcPagingItemReader" scope="step">
<property name="dataSource" ref="dataSource" />
<property name="queryProvider">
<bean
class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="selectClause" value="ID, IP, PORT, CONNECTED, BANNER, :partitionId as PARTITIONINFO" />
<property name="fromClause" value="FROM TARGET" />
<property name="whereClause" value="ID >= :minId AND ID <= :maxId AND CONNECTED IS NULL"/>
<property name="sortKey" value="ID" />
</bean>
</property>
<property name="pageSize" value="10" />
<property name="parameterValues">
<map>
<entry key="minId" value="#{stepExecutionContext[minValue]}"/>
<entry key="maxId" value="#{stepExecutionContext[maxValue]}"/>
<entry key="partitionId" value="#{stepExecutionContext[partitionId]}" />
</map>
</property>
<property name="rowMapper">
<bean class="com.michaelminella.springbatch.domain.TargetRowMapper"/>
</property>
</bean>
后来我在最后运行了更新查询并将详细信息保存在表中。
<bean id="targetWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="assertUpdates" value="true" />
<property name="itemSqlParameterSourceProvider">
<bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
<property name="sql" value="UPDATE TARGET SET CONNECTED = :connected, BANNER = :banner, PARTITIONINFO = :partitionId WHERE ID = :id" />
<property name="dataSource" ref="dataSource" />
</bean>
我已经向Target bean添加了一个新变量,它存储了partitionId信息。
private int partitionId;
public int getPartitionId() {
return partitionId;
}
public void setPartitionId(int partitionId) {
this.partitionId = partitionId;
}
business-schema-mysql.sql
DROP TABLE IF EXISTS TARGET;
CREATE TABLE TARGET (
ID BIGINT NOT NULL PRIMARY KEY ,
IP VARCHAR(15) NOT NULL,
PORT INT NOT NULL,
CONNECTED BOOLEAN NULL,
BANNER VARCHAR(255),
PARTITIONINFO INT
) ENGINE=InnoDB;