325.15. 본문 및 헤더를 텍스트로 저장
Camel 2.11에서 사용 가능
메시지 본문을 저장하고 (ed) 헤더를 별도의 열에서 String로 선택하도록 JdbcAggregationRepository 을 구성할 수 있습니다. 예를 들어 본문을 저장하고 다음 두 개의 헤더 companyName 및 accountName 은 다음 SQL을 사용합니다.
CREATE TABLE aggregationRepo3 ( id varchar(255) NOT NULL, exchange blob NOT NULL, body varchar(1000), companyName varchar(1000), accountName varchar(1000), constraint aggregationRepo3_pk PRIMARY KEY (id) ); CREATE TABLE aggregationRepo3_completed ( id varchar(255) NOT NULL, exchange blob NOT NULL, body varchar(1000), companyName varchar(1000), accountName varchar(1000), constraint aggregationRepo3_completed_pk PRIMARY KEY (id) );
그런 다음 다음과 같이 이 동작을 활성화하도록 리포지토리를 구성합니다.
<bean id="repo3"
class="org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository">
<property name="repositoryName" value="aggregationRepo3"/>
<property name="transactionManager" ref="txManager3"/>
<property name="dataSource" ref="dataSource3"/>
<!-- configure to store the message body and following headers as text in the repo -->
<property name="storeBodyAsText" value="true"/>
<property name="headersToStoreAsText">
<list>
<value>companyName</value>
<value>accountName</value>
</list>
</property>
</bean>325.15.1. codec (Serialization)
모든 유형의 페이로드를 포함할 수 있기 때문에 Exchange는 설계상 직렬화할 수 없습니다. 데이터베이스 BLOB 필드에 저장할 바이트 배열로 변환됩니다.It is converted into a byte array to be stored in a database BLOB field. 이러한 모든 변환은 JdbcCodec 클래스에서 처리합니다. 코드의 한 가지 세부 사항 중 하나는 주의가 필요합니다: ClassLoadingAwareObjectInputStream.
Apache ActiveMQ 프로젝트에서 ClassLoadingAwareObjectInput 이 재사용되었습니다. ObjectInputStream 을 래핑하고 현재Thread 대신 ContextClassLoader 와 함께 사용합니다. 다른 번들에서 노출하는 클래스를 로드할 수 있다는 이점이 있습니다. 이를 통해 교환 본문 및 헤더에 사용자 지정 유형 오브젝트 참조가 있을 수 있습니다.