提交 281a21b8 编写于 作者: C Calvin

#57 删除POI excel演示及activemq配置演示

上级 24c2e7cf
package org.springside.examples.showcase.utilities.excel;
/**
* 报表演示的模拟数据提供类.
*
* @author calvin
*/
public class DummyDataGenerator {
public static TemperatureAnomaly[] getDummyData() {
return new TemperatureAnomaly[] { new TemperatureAnomaly(1970, -0.068, -0.108),
new TemperatureAnomaly(1971, -0.190, -0.104), new TemperatureAnomaly(1972, -0.056, -0.100),
new TemperatureAnomaly(1973, 0.077, -0.097), new TemperatureAnomaly(1974, -0.213, -0.091),
new TemperatureAnomaly(1975, -0.170, -0.082), new TemperatureAnomaly(1976, -0.254, -0.068),
new TemperatureAnomaly(1977, 0.019, -0.050), new TemperatureAnomaly(1978, -0.063, -0.028),
new TemperatureAnomaly(1979, 0.050, -0.006), new TemperatureAnomaly(1980, 0.077, 0.015),
new TemperatureAnomaly(1981, 0.120, 0.032), new TemperatureAnomaly(1982, 0.011, 0.046),
new TemperatureAnomaly(1983, 0.177, 0.058), new TemperatureAnomaly(1984, -0.021, 0.069),
new TemperatureAnomaly(1985, -0.037, 0.081), new TemperatureAnomaly(1986, 0.030, 0.094),
new TemperatureAnomaly(1987, 0.179, 0.108), new TemperatureAnomaly(1988, 0.180, 0.123),
new TemperatureAnomaly(1989, 0.104, 0.137), new TemperatureAnomaly(1990, 0.255, 0.150),
new TemperatureAnomaly(1991, 0.210, 0.163), new TemperatureAnomaly(1992, 0.065, 0.178),
new TemperatureAnomaly(1993, 0.110, 0.195), new TemperatureAnomaly(1994, 0.172, 0.216),
new TemperatureAnomaly(1995, 0.269, 0.241), new TemperatureAnomaly(1996, 0.141, 0.268),
new TemperatureAnomaly(1997, 0.353, 0.296), new TemperatureAnomaly(1998, 0.548, 0.323),
new TemperatureAnomaly(1999, 0.298, 0.348) };
}
/**
* 年度气温记录类.
*
* @author calvin
*/
public static class TemperatureAnomaly {
private int year;
private double anomaly;
private double smoothed;
public TemperatureAnomaly(int year, double anomaly, double smoothed) {
this.year = year;
this.anomaly = anomaly;
this.smoothed = smoothed;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getAnomaly() {
return anomaly;
}
public void setAnomaly(double anomaly) {
this.anomaly = anomaly;
}
public double getSmoothed() {
return smoothed;
}
public void setSmoothed(double smoothed) {
this.smoothed = smoothed;
}
}
}
package org.springside.examples.showcase.utilities.excel;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.joda.time.DateTime;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springside.examples.showcase.utilities.excel.DummyDataGenerator.TemperatureAnomaly;
import org.springside.modules.web.Servlets;
import com.google.common.collect.Maps;
/**
* 基于POI导出Excel文件的Controller.
*
* @author calvin
*/
@Controller
public class ExcelExportController {
private Map<String, CellStyle> styles;
private int rowIndex = 0;
/**
* 生成Excel格式的内容.
*/
@RequestMapping(value = "/excel/export")
public void export(HttpServletResponse response) throws Exception {
//生成Excel文件.
Workbook wb = exportExcelWorkbook();
//输出Excel文件.
response.setContentType(Servlets.EXCEL_TYPE);
Servlets.setFileDownloadHeader(response, "温度年表.xls");
wb.write(response.getOutputStream());
response.getOutputStream().flush();
}
private Workbook exportExcelWorkbook() {
TemperatureAnomaly[] temperatureAnomalyArray = DummyDataGenerator.getDummyData();
//创建Workbook
Workbook wb = new HSSFWorkbook();
//创建所有Cell Style
createStyles(wb);
//创建工作表.
Sheet s = wb.createSheet("1970-1999");
//设定冻结表头
s.createFreezePane(0, 2, 0, 2);
//设定所有Column宽度自动配合内容宽度
s.autoSizeColumn(0);
s.autoSizeColumn(1);
s.autoSizeColumn(2);
//产生标题
generateTitle(s);
//产生表头
generateHeader(s);
//产生内容
generateContent(s, temperatureAnomalyArray);
//产生合计
generateTotals(s);
return wb;
}
private void generateTitle(Sheet s) {
Row r = s.createRow(rowIndex++);
Cell c1 = r.createCell(0);
c1.setCellValue("Temperature Anomaly(1970-1999)");
c1.setCellStyle(styles.get("header"));
//合并单元格
s.addMergedRegion(CellRangeAddress.valueOf("$A$1:$C$1"));
}
private void generateHeader(Sheet s) {
Row r = s.createRow(rowIndex++);
CellStyle headerStyle = styles.get("header");
Cell c1 = r.createCell(0);
c1.setCellValue("Year");
c1.setCellStyle(headerStyle);
Cell c2 = r.createCell(1);
c2.setCellValue("Anomaly");
c2.setCellStyle(headerStyle);
Cell c3 = r.createCell(2);
c3.setCellValue("Smoothed");
c3.setCellStyle(headerStyle);
}
private void generateContent(Sheet s, TemperatureAnomaly[] temperatureAnomalys) {
CellStyle dateCellStyle = styles.get("dateCell");
CellStyle numberCellStyle = styles.get("numberCell");
for (TemperatureAnomaly temperatureAnomaly : temperatureAnomalys) {
Row r = s.createRow(rowIndex++);
Cell c1 = r.createCell(0);
c1.setCellValue(new DateTime(temperatureAnomaly.getYear(), 1, 1, 0, 0, 0, 0).toDate());
c1.setCellStyle(dateCellStyle);
Cell c2 = r.createCell(1);
c2.setCellValue(temperatureAnomaly.getAnomaly());
c2.setCellStyle(numberCellStyle);
Cell c3 = r.createCell(2);
c3.setCellValue(temperatureAnomaly.getSmoothed());
c3.setCellStyle(numberCellStyle);
}
}
private void generateTotals(Sheet s) {
Row r = s.createRow(rowIndex++);
CellStyle totalStyle = styles.get("total");
//Cell强行分行
Cell c1 = r.createCell(0);
c1.setCellStyle(totalStyle);
c1.setCellValue("合\n计");
//合计公式
Cell c2 = r.createCell(1);
c2.setCellStyle(totalStyle);
c2.setCellFormula("SUM(B3:B32)");
Cell c3 = r.createCell(2);
c3.setCellStyle(totalStyle);
c3.setCellFormula("SUM(C3:C32)");
}
private Map<String, CellStyle> createStyles(Workbook wb) {
styles = Maps.newHashMap();
DataFormat df = wb.createDataFormat();
// --字体设定 --//
//普通字体
Font normalFont = wb.createFont();
normalFont.setFontHeightInPoints((short) 10);
//加粗字体
Font boldFont = wb.createFont();
boldFont.setFontHeightInPoints((short) 10);
boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
//蓝色加粗字体
Font blueBoldFont = wb.createFont();
blueBoldFont.setFontHeightInPoints((short) 10);
blueBoldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
blueBoldFont.setColor(IndexedColors.BLUE.getIndex());
// --Cell Style设定-- //
//标题格式
CellStyle headerStyle = wb.createCellStyle();
headerStyle.setFont(boldFont);
styles.put("header", headerStyle);
//日期格式
CellStyle dateCellStyle = wb.createCellStyle();
dateCellStyle.setFont(normalFont);
dateCellStyle.setDataFormat(df.getFormat("yyyy"));
setBorder(dateCellStyle);
styles.put("dateCell", dateCellStyle);
//数字格式
CellStyle numberCellStyle = wb.createCellStyle();
numberCellStyle.setFont(normalFont);
numberCellStyle.setDataFormat(df.getFormat("#,##0.00"));
setBorder(numberCellStyle);
styles.put("numberCell", numberCellStyle);
//合计列格式
CellStyle totalStyle = wb.createCellStyle();
totalStyle.setFont(blueBoldFont);
totalStyle.setWrapText(true);
totalStyle.setAlignment(CellStyle.ALIGN_RIGHT);
setBorder(totalStyle);
styles.put("total", totalStyle);
return styles;
}
private void setBorder(CellStyle style) {
//设置边框
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
}
}
......@@ -19,28 +19,26 @@
<li>在JaxbDemo.java中演示XML与Java对象的转换及Dom4j的使用.</li>
<li>在JsonDemo.java中演示Jackson远超同类JSON库的转化能力.</li>
</ul>
<hr/>
<h3>Excel演示</h3>
<p>说明:演示基于POI的Excel操作。</p>
<ul>
<li><a href="/showcase/excel/export">导出Excel文件</a><br /> 演示冻结/合并单元格, 单元格字体/边框/颜色, 单元格数值格式/公式等特性.</li>
<li>读取Excel文件<br />见ExcelExportActionTest测试用例.</li>
</ul>
<hr/>
<h3>Email演示</h3>
<ul>
<li>简单文本邮件演示.</li>
<li>带附件的MIME邮件演示, 使用Freemarker模板创建HTML内容.</li>
<li>在综合演示用例中保存用户时,发送两种邮件.<br /> 演示邮箱名为springside3.demo@gmail.com, 密码为demoforyou.</li>
</ul>
<hr/>
<h3>日志演示</h3>
<ul>
<li>Log4JManager: 通过JMX动态查询与改变Logger的日志等级与Appender, 详见JMX页面.</li>
<li>Log4MockjAppender: 在测试用例中验证日志的输出, 在Schedule测试用例使用MockAppender校验日志输出.</li>
</ul>
<hr/>
<h3>其他常用工具</h3>
<p>全部演示在org.springside.examples.showcase.utilities目录</p>
<ul>
......
package org.springside.examples.showcase.excel;
import static org.junit.Assert.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
import org.junit.Test;
import org.springside.examples.showcase.utilities.excel.ExcelExportController;
import org.springside.modules.utils.Reflections;
/**
* 测试ExcelExportController测试, 演示Excel的读取.
*
* @author calvin
*/
public class ExcelExportControllerTest {
@Test
public void test() throws Exception {
ExcelExportController controller = new ExcelExportController();
Workbook wb = (Workbook) Reflections.invokeMethod(controller, "exportExcelWorkbook", null, null);
//按照Cell名称取得Cell,读取Cell的数值
CellReference cr = new CellReference("B3");
Cell cell1970 = wb.getSheetAt(0).getRow(cr.getRow()).getCell(cr.getCol());
assertEquals(-0.068, cell1970.getNumericCellValue(), 0.01);
//按照Cell的坐标取得Cell,读取Cell的公式计算结果.
Cell cellTotal = wb.getSheetAt(0).getRow(32).getCell(1);
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(2.373, evaluator.evaluate(cellTotal).getNumberValue(), 0.01);
}
}
Configuration Tunning for ActiveMQ.
1.bin/active-admin.sh: uncomment JMX options and set JMX port to 1616.
set max memory from 512M to 2048M, and set new generation memory size.
2.conf/activemq.xml: set <system usage>, 1)memory from 20m to 512m, 2)disk from 1g to 10g, 3)temp from 100mb to 1g
set <destinationPolicy> memory limit from 1m to 32m
3.conf/activemq-network-broker-1.xml:set networkConnector and transportConnector multicast from default to special group name.
set right broker name.
copy configuration from activemq.xml
4.conf/jetty.xml: remove demo,camel and fileserver application.
#!/bin/sh
# ------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
# load system-wide activemq configuration
if [ -f "/etc/activemq.conf" ] ; then
. /etc/activemq.conf
fi
# provide default values for people who don't use RPMs
if [ -z "$usejikes" ] ; then
usejikes=false;
fi
# load user activemq configuration
if [ -f "$HOME/.activemqrc" ] ; then
. "$HOME/.activemqrc"
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
Darwin*) darwin=true
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
fi
;;
esac
if [ -z "$ACTIVEMQ_HOME" ] ; then
# try to find ACTIVEMQ
if [ -d /opt/activemq ] ; then
ACTIVEMQ_HOME=/opt/activemq
fi
if [ -d "${HOME}/opt/activemq" ] ; then
ACTIVEMQ_HOME="${HOME}/opt/activemq"
fi
## resolve links - $0 may be a link to activemq's home
PRG="$0"
progname=`basename "$0"`
saveddir=`pwd`
# need this for relative symlinks
dirname_prg=`dirname "$PRG"`
cd "$dirname_prg"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
ACTIVEMQ_HOME=`dirname "$PRG"`/..
cd "$saveddir"
# make it fully qualified
ACTIVEMQ_HOME=`cd "$ACTIVEMQ_HOME" && pwd`
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$ACTIVEMQ_HOME" ] &&
ACTIVEMQ_HOME=`cygpath --unix "$ACTIVEMQ_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD=`which java 2> /dev/null `
if [ -z "$JAVACMD" ] ; then
JAVACMD=java
fi
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi
if [ -z "$ACTIVEMQ_BASE" ] ; then
ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
ACTIVEMQ_HOME=`cygpath --windows "$ACTIVEMQ_HOME"`
ACTIVEMQ_BASE=`cygpath --windows "$ACTIVEMQ_BASE"`
ACTIVEMQ_CLASSPATH=`cygpath --path --windows "$ACTIVEMQ_CLASSPATH"`
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
CYGHOME=`cygpath --windows "$HOME"`
fi
# Set default classpath
ACTIVEMQ_CLASSPATH="${ACTIVEMQ_BASE}/conf;"$ACTIVEMQ_CLASSPATH
if [ $1 = "start" ] ; then
if [ -z "$ACTIVEMQ_OPTS" ] ; then
ACTIVEMQ_OPTS="-Xms2048M -Xmx2048M -Xmn768M -XX:MaxPermSize=96M -Dorg.apache.activemq.UseDedicatedTaskRunner=true -Djava.util.logging.config.file=logging.properties"
fi
if [ -z "$SUNJMX" ] ; then
SUNJMX="-Dcom.sun.management.jmxremote.port=1616 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
#SUNJMX="-Dcom.sun.management.jmxremote"
fi
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $SUNJMX $SSL_OPTS"
fi
# Uncomment to enable YourKit profiling
#ACTIVEMQ_DEBUG_OPTS="-agentlib:yjpagent"
# Uncomment to enable remote debugging
#ACTIVEMQ_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
if [ -n "$CYGHOME" ]; then
exec "$JAVACMD" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS -Dactivemq.classpath="${ACTIVEMQ_CLASSPATH}" -Dactivemq.home="${ACTIVEMQ_HOME}" -Dactivemq.base="${ACTIVEMQ_BASE}" -Dcygwin.user.home="$CYGHOME" -jar "${ACTIVEMQ_HOME}/bin/run.jar" $@
else
exec "$JAVACMD" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS -Dactivemq.classpath="${ACTIVEMQ_CLASSPATH}" -Dactivemq.home="${ACTIVEMQ_HOME}" -Dactivemq.base="${ACTIVEMQ_BASE}" -jar "${ACTIVEMQ_HOME}/bin/run.jar" $@
fi
<!--
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You
under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- Allows us to use system properties as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.base}/conf/credentials.properties</value>
</property>
</bean>
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq1" dataDirectory="${activemq.base}/data"
destroyApplicationContextOnStop="true">
<!--
For better performances use VM cursor and small memory limit. For more information, see:
http://activemq.apache.org/message-cursors.html Also, if your producer is "hanging", it's probably due to producer
flow control. For more information, see: http://activemq.apache.org/producer-flow-control.html
-->
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="32mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="32mb">
<!--
Use VM cursor for better latency For more information, see: http://activemq.apache.org/message-cursors.html
<pendingQueuePolicy> <vmQueueCursor/> </pendingQueuePolicy>
-->
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!--
The managementContext is used to configure how ActiveMQ is exposed in JMX. By default, ActiveMQ uses the MBean server
that is started by the JVM. For more information, see: http://activemq.apache.org/jmx.html
-->
<managementContext>
<managementContext createConnector="false" />
</managementContext>
<!--
Configure network connector to use multicast protocol For more information, see
http://activemq.apache.org/multicast-transport-reference.html
-->
<networkConnectors>
<networkConnector uri="multicast://239.255.2.3:6155?group=springside" dynamicOnly="true" networkTTL="3" prefetchSize="1" />
</networkConnectors>
<!--
Configure message persistence for the broker. The default persistence mechanism is the KahaDB store (identified by
the kahaDB tag). For more information, see: http://activemq.apache.org/persistence.html
-->
<persistenceAdapter>
<kahaDB directory="${activemq.base}/data/kahadb" />
</persistenceAdapter>
<!--
The systemUsage controls the maximum amount of space the broker will use before slowing down producers. For more
information, see: http://activemq.apache.org/producer-flow-control.html
-->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="512 mb" />
</memoryUsage>
<storeUsage>
<storeUsage limit="10 gb" name="foo" />
</storeUsage>
<tempUsage>
<tempUsage limit="1 gb" />
</tempUsage>
</systemUsage>
</systemUsage>
<!--
The transport connectors expose ActiveMQ over a given protocol to clients and other brokers. For more information,
see: http://activemq.apache.org/configuring-transports.html
-->
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" discoveryUri="multicast://239.255.2.3:6155?group=springside" />
</transportConnectors>
</broker>
<!--
Enable web consoles, REST and Ajax APIs and demos Take a look at activemq-jetty.xml for more details
-->
<import resource="jetty.xml" />
</beans>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You
under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- Allows us to use system properties as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.base}/conf/credentials.properties</value>
</property>
</bean>
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq2" dataDirectory="${activemq.base}/data"
destroyApplicationContextOnStop="true">
<!--
For better performances use VM cursor and small memory limit. For more information, see:
http://activemq.apache.org/message-cursors.html Also, if your producer is "hanging", it's probably due to producer
flow control. For more information, see: http://activemq.apache.org/producer-flow-control.html
-->
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="32mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="32mb">
<!--
Use VM cursor for better latency For more information, see: http://activemq.apache.org/message-cursors.html
<pendingQueuePolicy> <vmQueueCursor/> </pendingQueuePolicy>
-->
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!--
The managementContext is used to configure how ActiveMQ is exposed in JMX. By default, ActiveMQ uses the MBean server
that is started by the JVM. For more information, see: http://activemq.apache.org/jmx.html
-->
<managementContext>
<managementContext createConnector="false" />
</managementContext>
<!--
Configure network connector to use multicast protocol For more information, see
http://activemq.apache.org/multicast-transport-reference.html
-->
<networkConnectors>
<networkConnector uri="multicast://239.255.2.3:6155?group=springside" dynamicOnly="true" networkTTL="3" prefetchSize="1" />
</networkConnectors>
<!--
Configure message persistence for the broker. The default persistence mechanism is the KahaDB store (identified by
the kahaDB tag). For more information, see: http://activemq.apache.org/persistence.html
-->
<persistenceAdapter>
<kahaDB directory="${activemq.base}/data/kahadb" />
</persistenceAdapter>
<!--
The systemUsage controls the maximum amount of space the broker will use before slowing down producers. For more
information, see: http://activemq.apache.org/producer-flow-control.html
-->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="512 mb" />
</memoryUsage>
<storeUsage>
<storeUsage limit="10 gb" name="foo" />
</storeUsage>
<tempUsage>
<tempUsage limit="1 gb" />
</tempUsage>
</systemUsage>
</systemUsage>
<!--
The transport connectors expose ActiveMQ over a given protocol to clients and other brokers. For more information,
see: http://activemq.apache.org/configuring-transports.html
-->
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" discoveryUri="multicast://239.255.2.3:6155?group=springside" />
</transportConnectors>
</broker>
<!--
Enable web consoles, REST and Ajax APIs and demos Take a look at activemq-jetty.xml for more details
-->
<import resource="jetty.xml" />
</beans>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You
under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- Allows us to use system properties as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.base}/conf/credentials.properties</value>
</property>
</bean>
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.base}/data"
destroyApplicationContextOnStop="true">
<!--
For better performances use VM cursor and small memory limit. For more information, see:
http://activemq.apache.org/message-cursors.html Also, if your producer is "hanging", it's probably due to producer
flow control. For more information, see: http://activemq.apache.org/producer-flow-control.html
-->
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true" memoryLimit="32mb">
<pendingSubscriberPolicy>
<vmCursor />
</pendingSubscriberPolicy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="32mb">
<!--
Use VM cursor for better latency For more information, see: http://activemq.apache.org/message-cursors.html
<pendingQueuePolicy> <vmQueueCursor/> </pendingQueuePolicy>
-->
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!--
The managementContext is used to configure how ActiveMQ is exposed in JMX. By default, ActiveMQ uses the MBean server
that is started by the JVM. For more information, see: http://activemq.apache.org/jmx.html
-->
<managementContext>
<managementContext createConnector="false" />
</managementContext>
<!--
Configure message persistence for the broker. The default persistence mechanism is the KahaDB store (identified by
the kahaDB tag). For more information, see: http://activemq.apache.org/persistence.html
-->
<persistenceAdapter>
<kahaDB directory="${activemq.base}/data/kahadb" />
</persistenceAdapter>
<!--
The systemUsage controls the maximum amount of space the broker will use before slowing down producers. For more
information, see: http://activemq.apache.org/producer-flow-control.html
-->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="512 mb" />
</memoryUsage>
<storeUsage>
<storeUsage limit="10 gb" name="foo" />
</storeUsage>
<tempUsage>
<tempUsage limit="1 gb" />
</tempUsage>
</systemUsage>
</systemUsage>
<!--
The transport connectors expose ActiveMQ over a given protocol to clients and other brokers. For more information,
see: http://activemq.apache.org/configuring-transports.html
-->
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" />
</transportConnectors>
</broker>
<!--
Enable web consoles, REST and Ajax APIs and demos Take a look at activemq-jetty.xml for more details
-->
<import resource="jetty.xml" />
</beans>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to You under
the Apache License, Version 2.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
agreed to in writing, software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
An embedded servlet engine for serving up the Admin consoles, REST and Ajax APIs and
some demos Include this file in your configuration to enable ActiveMQ web components
e.g. <import resource="jetty.xml"/>
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="securityLoginService" class="org.eclipse.jetty.security.HashLoginService">
<property name="name" value="ActiveMQRealm" />
<property name="config" value="${activemq.base}/conf/jetty-realm.properties" />
</bean>
<bean id="securityConstraint" class="org.eclipse.jetty.http.security.Constraint">
<property name="name" value="BASIC" />
<property name="roles" value="admin" />
<property name="authenticate" value="false" />
</bean>
<bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="securityConstraint" />
<property name="pathSpec" value="/*" />
</bean>
<bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<property name="loginService" ref="securityLoginService" />
<property name="authenticator">
<bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator" />
</property>
<property name="constraintMappings">
<list>
<ref bean="securityConstraintMapping" />
</list>
</property>
<property name="handler">
<bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.webapp.WebAppContext">
<property name="contextPath" value="/admin" />
<property name="resourceBase" value="${activemq.home}/webapps/admin" />
<property name="logUrlOnStart" value="true" />
</bean>
<bean class="org.eclipse.jetty.server.handler.ResourceHandler">
<property name="directoriesListed" value="false" />
<property name="welcomeFiles">
<list>
<value>index.html</value>
</list>
</property>
<property name="resourceBase" value="${activemq.home}/webapps/" />
</bean>
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler">
<property name="serveIcon" value="false" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
</bean>
<bean id="Server" class="org.eclipse.jetty.server.Server" init-method="start"
destroy-method="stop">
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<property name="port" value="8161" />
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<ref bean="contexts" />
<ref bean="securityHandler" />
</list>
</property>
</bean>
</property>
</bean>
</beans>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册