Wednesday, November 29, 2017

visual code add quick debug profile to go lang project

visual code add quick debug profile to go lang project

how to it:
in vs code > vscode/launch.json file, add below code:    (or used left debug panel > add profile)

    {
        "name": "xg",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "remotePath": "",
        "port": 8086,
        "host": "127.0.0.1",
        "program": "${env:GOPATH}/src/sx98/xg/main.go",
        "cwd": "${env:GOPATH}/src/sx98/xg/",
        "env": {},
        "args": [],
        "showLog": true
    }

Then, in left debug panel, choose "xg", now can debug quickly. From now, no need locate to "src/sx98/xg/main.go" and press F5.


Tuesday, November 28, 2017

go lang, cannot use columns (type []string) as type string in argument to string

i want to used type []string to ...string when call some function with variable parameters. in go lang code.

write below code:

func f(p ...string){
    // ...
}

correct code:
var p []string
f(p...)

error code:
var p []string
f(p)

it said:
cannot use columns (type []string) as type string in argument to string

Sunday, August 27, 2017

apache camel with spring boot develop some draft - camel-quickfix-starter

1. create fix client communicate with fix server used camel-quickfix-starter
pom.xml:
  
  <dependency>
   <groupId>org.apache.camel</groupId>
   <artifactId>camel-ahc-ws-starter</artifactId>
   <version>2.19.2</version>
  </dependency>
  

application.xml:
my:
  okcoin:
    wsuri: wss://real.okcoin.cn:10440/websocket/okcoinapi
    cfg: okcoin
    sessionID: ?sessionID=FIX.4.4:f75dcc4d-13fa-4118-a908-050b530f6913->OKSERVER
    userName: f75dcc4d-13fa-4118-a908-050b530f6913
    password: MY_OKCOIN_PASSWORD

src/main/resources/okcoin/inprocess.cfg:
[session]
BeginString=FIX.4.4
#FileStorePath=data/okclient
#FileLogPath=data/okclientlog
ConnectionType=initiator
TargetCompID=OKSERVER
StartTime=00:00:00
EndTime=00:00:00
HeartBtInt=30
ReconnectInterval=5
UseDataDictionary=Y
DataDictionary=okcoin/FIX44.xml
ResetOnLogon=Y
ResetOnLogout=Y
FileStoreMaxCachedMsgs=10
ResetOnDisconnect=Y
ResetOnError=Y
SocketUseSSL=Y
ValidateUserDefinedFields=N
SenderCompID=f75dcc4d-13fa-4118-a908-050b530f6913

# 中国站
SocketConnectHost=fix.okcoin.cn
SocketConnectPort=9880

#国际站
# SocketConnectHost=api.okcoin.cn
# SocketConnectPort=9880

QFixConfig.java:
package com.hx98.server.config;

import java.io.Serializable;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component  
@ConfigurationProperties(prefix="my") 
public class QFixConfig {
 
 public static final class Service implements Serializable{
  private static final long serialVersionUID = 1L;

  private Integer minStartRqtId = 111111111;
  private Integer maxStartRqtId = 999999999;
  
  private String wsuri;
  private String cfg;
  private String sessionID;
  private String userName;
  private String password;
  
  public String getCfg() {
   return cfg;
  }
  public void setCfg(String cfg) {
   this.cfg = cfg;
  }
  public String getUserName() {
   return userName;
  }
  public void setUserName(String userName) {
   this.userName = userName;
  }
  public String getPassword() {
   return password;
  }
  public void setPassword(String password) {
   this.password = password;
  }
  public Integer getMinStartRqtId() {
   return minStartRqtId;
  }
  public void setMinStartRqtId(Integer minStartRqtId) {
   this.minStartRqtId = minStartRqtId;
  }
  public Integer getMaxStartRqtId() {
   return maxStartRqtId;
  }
  public void setMaxStartRqtId(Integer maxStartRqtId) {
   this.maxStartRqtId = maxStartRqtId;
  }
  public String getSessionID() {
   return sessionID;
  }
  public void setSessionID(String sessionID) {
   this.sessionID = sessionID;
  }
  public String getWsuri() {
   return wsuri;
  }
  public void setWsuri(String wsuri) {
   this.wsuri = wsuri;
  }
 }
 
 private Service okcoin = new Service();

 public Service getOkcoin() {
  return okcoin;
 }

 public void setOkcoin(Service okcoin) {
  this.okcoin = okcoin;
 }
}

FixApi.java:
package com.hx98.server.api.okcoin;

import java.util.concurrent.CountDownLatch;

import org.apache.camel.CamelContext;
import org.apache.camel.CamelExchangeException;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Handler;
import org.apache.camel.Producer;
import org.apache.camel.builder.PredicateBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.quickfixj.QuickfixjEndpoint;
import org.apache.camel.component.quickfixj.QuickfixjEventCategory;
import org.apache.log4j.Logger;

import com.hx98.server.api.FinanceFetchBaseApi;
import com.hx98.server.config.QFixConfig;
import com.hx98.server.transform.QuickfixjEventJsonTransformer;
import com.hx98.server.utils.CountDownLatchDecrementer;

import quickfix.ConfigError;
import quickfix.FieldNotFound;
import quickfix.Message;
import quickfix.RejectLogon;
import quickfix.field.MsgType;
import quickfix.field.RawData;
import quickfix.fix44.Logon;
import quickfix.fix44.MarketDataRequest;

public class FixApi extends RouteBuilder {

 private static final Logger log = Logger.getLogger(FixApi.class);

 final CountDownLatch logoutLatch = new CountDownLatch(1);

 private CamelContext camelContext;

//  @Bean
//  String myBean() {
//      return "I'm Spring bean!";
//  }
 
 @Override
 public void configure() { 
  final String tradeName = getOkcoinConfig().getCfg();

  camelContext = getContext();

  // from("timer:trigger")
  // .transform().simple("ref:myBean")
  // .to("log:out");

  try {
   from("quickfix:" + tradeName + "/inprocess.cfg")
     .filter(PredicateBuilder.and(
       header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
         .isEqualTo(QuickfixjEventCategory.AdminMessageSent),
       header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.LOGON)))
     .bean(new CredentialInjector());

   from("quickfix:" + tradeName + "/inprocess.cfg")
     .filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
       .isEqualTo(QuickfixjEventCategory.SessionLogoff))
     .bean(new CountDownLatchDecrementer("logout", logoutLatch));

   from("quickfix:" + tradeName + "/inprocess.cfg")
     .filter(PredicateBuilder.or(
       header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
         .isEqualTo(QuickfixjEventCategory.AdminMessageSent),
       header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
         .isEqualTo(QuickfixjEventCategory.AppMessageSent),
       header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
         .isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
       header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
         .isEqualTo(QuickfixjEventCategory.AppMessageReceived)))
     .bean(new QuickfixjEventJsonTransformer()).to("log:routing");

   from("quickfix:" + tradeName + "/inprocess.cfg")
     .filter(PredicateBuilder.and(
       header(QuickfixjEndpoint.EVENT_CATEGORY_KEY)
         .isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
       header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.LOGON)))
     .bean(new LogonAuthenticator());

   from("quickfix:" + tradeName + "/inprocess.cfg").filter(routeBuilder
     .header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon))
     .bean(new SessionLogon());

   from("quickfix:" + tradeName + "/inprocess.cfg")
     .filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY)
       .isEqualTo(MsgType.MARKET_DATA_SNAPSHOT_FULL_REFRESH))
     .bean(new QuickfixjEventJsonTransformer())
     .to("rabbitmq:rmq-srv/finance.quote")
     //.to("websocket://0.0.0.0:8082/jfix")
     ;

  } catch (ConfigError e) {
   e.printStackTrace();
  }
 }

 private static Integer curRqtId = null;

 private String generateRequestId() {
  QFixConfig.Service okcoinConfig = getOkcoinConfig();

  if (curRqtId == null) {
   curRqtId = okcoinConfig.getMinStartRqtId();
  }
  Integer ret = curRqtId++;
  if (curRqtId > okcoinConfig.getMaxStartRqtId())
   curRqtId = okcoinConfig.getMinStartRqtId();
  return ret.toString();
 }

 public static class LogonAuthenticator {
  @Handler
  public void authenticate(Exchange exchange) throws RejectLogon, CamelExchangeException, FieldNotFound {
   log.info("LogonAuthenticator Acceptor is logon for "
     + exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY));
   Message message = exchange.getIn().getMandatoryBody(Message.class);
   if (message.isSetField(RawData.FIELD)) {
    log.info("LogonAuthenticator body: " + message.getString(RawData.FIELD));
   }
  }
 }

 public class SessionLogon {
  @Handler
  public void logon(Exchange exchange) throws RejectLogon, CamelExchangeException, FieldNotFound {

   log.info("logon is received!");

   MarketDataRequest marketDataRequest = new MarketDataRequest(new quickfix.field.MDReqID(generateRequestId()),
     new quickfix.field.SubscriptionRequestType(
       quickfix.field.SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES),
     new quickfix.field.MarketDepth(1));

   final char[] fields = new char[] { quickfix.field.MDEntryType.OPENING_PRICE,
     quickfix.field.MDEntryType.CLOSING_PRICE, quickfix.field.MDEntryType.TRADING_SESSION_HIGH_PRICE,
     quickfix.field.MDEntryType.TRADING_SESSION_LOW_PRICE,
     quickfix.field.MDEntryType.TRADING_SESSION_VWAP_PRICE, quickfix.field.MDEntryType.TRADE_VOLUME };

   MarketDataRequest.NoMDEntryTypes noMDEntryTypes = new MarketDataRequest.NoMDEntryTypes();
   for (char f : fields) {
    noMDEntryTypes.set(new quickfix.field.MDEntryType(f));
    marketDataRequest.addGroup(noMDEntryTypes);
   }

   final String[] symbols = new String[] { "BTC/CNY" }; // , "LTC/CNY"
                 // only 1

   MarketDataRequest.NoRelatedSym noRelatedSym = new MarketDataRequest.NoRelatedSym();
   for (String symbol : symbols) {
    noRelatedSym.setField(new quickfix.field.Symbol(symbol));
    marketDataRequest.addGroup(noRelatedSym);
   }

   marketDataRequest.setField(new quickfix.field.MDUpdateType(quickfix.field.MDUpdateType.FULL_REFRESH));

   // exchange.getOut().setBody(marketDataRequest);

   // above row can not worked.
   // below is create one new exchange messge and send messge to
   // server.
   send(marketDataRequest);
  }

 }

 private Endpoint requestEndpoint;
 private Producer requestProducer;

 public void send(Message message) {
  try {
   QFixConfig.Service okcoinConfig = getOkcoinConfig();

   if (requestEndpoint == null) {
    String marketUri = "quickfix:" + okcoinConfig.getCfg() + "/inprocess.cfg" + okcoinConfig.getSessionID();
    requestEndpoint = camelContext.getEndpoint(marketUri);
   }
   if (requestProducer == null) {
    requestProducer = requestEndpoint.createProducer();
   }
   Exchange requestExchange = requestEndpoint.createExchange(ExchangePattern.InOnly);
   requestExchange.getIn().setBody(message);
   requestProducer.process(requestExchange);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 public class CredentialInjector {
  @Handler
  public void inject(Exchange exchange) throws CamelExchangeException {
   QFixConfig.Service okcoinConfig = getOkcoinConfig();

   log.info("Injecting password into outgoing logon message");
   Message message = exchange.getIn().getMandatoryBody(Message.class);
   Logon logon = (Logon) message;
   String s;

   s = okcoinConfig.getUserName();
   if ((s != null) && (!s.isEmpty()))
    logon.setField(new quickfix.field.Username(s));

   s = okcoinConfig.getPassword();
   if ((s != null) && (!s.isEmpty()))
    logon.setField(new quickfix.field.Password(s));
  }
 }
}


QuickfixjEventJsonTransformer.java:
package com.hx98.server.transform;

import org.apache.camel.Exchange;
import org.apache.camel.Handler;
import org.apache.camel.component.quickfixj.QuickfixjEndpoint;

import quickfix.ConfigError;
import quickfix.DataDictionary;
import quickfix.Message;
import quickfix.Session;
import quickfix.SessionID;

public class QuickfixjEventJsonTransformer {
    private final QuickfixjMessageJsonTransformer renderer;
    
    public QuickfixjEventJsonTransformer() throws ConfigError {
        renderer = new QuickfixjMessageJsonTransformer();
    }
    
    @Handler
    public String transform(Exchange exchange) {
        SessionID sessionID = exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY, SessionID.class);
        Session session = Session.lookupSession(sessionID);
        DataDictionary dataDictionary = session.getDataDictionary();
        
        if (dataDictionary == null) {
            throw new IllegalStateException("No Data Dictionary. Exchange must reference an existing session");
        }
        
        StringBuilder sb = new StringBuilder();
        sb.append("\"event\": {\n");
        
        org.apache.camel.Message in = exchange.getIn();
        for (String key : in.getHeaders().keySet()) {
            sb.append("  \"").append(key).append("\": ").append(in.getHeader(key)).append(",\n");                
        }
        
        sb.append(renderer.transform(in.getBody(Message.class), "  ", dataDictionary)).append("\n");
        sb.append("}\n");
        return sb.toString();
    }
}

Last:
Thanks!

Thursday, July 6, 2017

docker command simple summary

normal old local docker operator command:
$ docker create | stop | ps | rm

docker swarm machine operator command:
$ docker-machine create | stop | rm | ls

docker swarm operator command on machine:
$ docker swarm init | join-token | leave | join

docket network operator command on machine:
$ docket network ls | create | inspect | rm

single docker with docker-compose.yml or docker-compose.yaml:
$ docker-compose create | rm | start | stop | up

docker swarm with compose file:
$ docker stack deploy | ps | rm | services

docket swarm container service operator command in manager role of swarm machine:
$ docker service ls | create | rm | logs

docker list swarm node in manager role of swarm machine:
$ docker node ls

show consul run statist.(consul is service name)
$ docker service ps consul

$ docker exec -it $(docker ps | grep "pkrss-microsrv-consul" | awk {'print $1'}) ping consul-default

$ docker network inspect ingress

delete consul service:
$ docker service rm $(docker service ls | grep consul | awk '{print $1}')

create service on worker machine:
$ docker service create --name foo6 --constraint="node.role == worker" --network foo alpine sleep 999999

Last

docker swarm mode default by boot2docker method can not access ping each container service

docker swarm mode default by boot2docker method can not ping each container service

so before we create our swarm service, we need create our overlay network:
$ docker network create --driver overlay my-net

then create service with  parameter "--network my-net".
for example:
$ docker service create --replicas 1 --name consul --network my-net -p 8300:8300 -p 8301:8301 -p 8301:8301/udp -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600 consul agent -server -bootstrap-expect 1 -ui -client 0.0.0.0 -advertise 192.168.3.132 -node=swarm1

Last:
Thanks!

Wednesday, July 5, 2017

com.spotify docker-maven-plugin used error and problem draft


My xml with:


 <properties>
        <docker.image.prefix>springio</docker.image.prefix>
        <docker.plugin.version>1.0.0</docker.plugin.version>
        <docker.repostory>192.168.3.131:5000</docker.repostory>
        <DOCKER_HOST>tcp://192.168.3.131:2376</DOCKER_HOST>
 </properties>

<build>      

       <plugins>

           <plugin>

               <groupId>org.springframework.boot</groupId>

               <artifactId>spring-boot-maven-plugin</artifactId>

               <executions>

                   <execution>

                       <goals>

                           <goal>repackage</goal>

                       </goals>

                   </execution>

               </executions>

           </plugin>

           <plugin>

               <groupId>com.spotify</groupId>

               <artifactId>docker-maven-plugin</artifactId>

               <version>${docker.plugin.version}</version>

              

               <configuration>

                   <imageName>${project.artifactId}</imageName>

                   <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>

                   <resources>

                       <resource>

                           <targetPath>/</targetPath>

                           <directory>${project.build.directory}</directory>

                           <include>${project.build.finalName}.jar</include>

                       </resource>

                   </resources>

               </configuration>

              

               <executions>

                 <execution>

          <id>build-image</id>

          <phase>package</phase>

          <goals>

            <goal>build</goal>

          </goals>

        </execution>

        <execution>

          <id>tag-image</id>

          <phase>package</phase>

          <goals>

            <goal>tag</goal>

          </goals>

                   <configuration>

                    <image>${project.artifactId}</image>

                     <newName>${docker.repostory}/${project.artifactId}</newName>

                   </configuration>

        </execution>

        <execution>

          <id>push-image</id>

          <phase>deploy</phase>

          <goals>

            <goal>push</goal>

          </goals>

          <configuration>

            <imageName>${docker.repostory}/${project.artifactId}</imageName>

          </configuration>

        </execution>

               </executions>

           </plugin>

       </plugins>

   </build>


Error:
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:tag (default-cli) on project pkrss-microsrv-consul:
 The parameters 'image', 'newName' for goal com.spotify:docker-maven-plugin:1.0.0:tag are missing or invalid -> [Help 1]

Why:
i used below command, and lost package.
$ mvn docker:tag -D pushImage


Error:
The push registry is docker.io not my self local registry responsity.
The push refers to a repository [docker.io/library/pkrss-microsrv-consul]


Why:
i used below command, and not have docker:build:
mvn package docker:tag -D pushImage

Suggest:

$ mvn clean package docker:build -D pushImageTags
clean command also can skip.
It is ok.

Last:
Thanks!

Tuesday, July 4, 2017

docker container images delete command summary

Docker container images delete command summary

1.show all docker container:
$ docker ps -a -q
stop all running container:
docker stop $(docker ps -a -q)
then you can delete all images:
$ docker rm $(docker ps -a -q)
2.show all images:
$ docker images
3.delete one image by id:
$ docker rmi <image id>
delete untagged images, which id is <None>:
$ docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
delete all images:
$ docker rmi $(docker images -q)
last
thanks!

2 docker machine add 2 consul instance

What
i run 2 docker machine , and want to instance each consul in each machine.

How

1. first machine is leader and it's ip is 192.168.3.131

docker run --restart=always -d -v /data:/data -p 8300:8300 -p 8301:8301 -p 8301:8301/udp -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600 consul agent -server -bootstrap-expect 2 -ui -client 0.0.0.0 -advertise 192.168.3.131 -node=local


2. second machine is slave and it's ip is 192.168.3.132

docker run --restart=always -d -v /data:/data -p 8300:8300 -p 8301:8301 -p 8301:8301/udp -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600 consul agent -server -ui -client 0.0.0.0 -advertise 192.168.3.132 -node=master1 -join 192.168.3.131



Other
> Error:  network may be misconfigured
> Error:  foreign ip cannot access http://192.168.3.131:8500/ui/
add
-p 8300:8300 -p 8301:8301 -p 8301:8301/udp -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600


>

Thursday, June 15, 2017

every one access tomcat web directory add authentication

i want to add xxx web directory in tomcat with specify user and password access.

webapps/xxx/WEB-INF/web.xml:
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>HTML Manager interface (for humans)</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-my</role-name>
    </auth-constraint>
  </security-constraint> 
   <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Tomcat Manager Application</realm-name>
  </login-config>

conf/tomcat-users.xml:
  
<role rolename="manager-my">
  <user password="hx98.com.cn" roles="manager-my" username="hx98">
</user></role>

restart tomcat . ok!

Saturday, June 3, 2017

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

below is my mysql(MariaDB) server stored procedure code


# call `pkrss_get_rssitem_vo`(2, 0, 0, 0, 1, 0, 0, 0);
#   flag = 1: select items
#   flag =-1: select items count
#   flag = 2: select items with image mode
#   flag =-2: select items with image mode count
#   flag = 3: get top 1 item with each table
#   flag = 4: get top n item with each table
CREATE PROCEDURE `pkrss_get_rssitem_vo`(IN `lid` INT, IN `cid` INT, IN `tid` INT, IN `offset` INT, IN `limit` INT, IN `idOrderBy` INT, IN `timeOrderBy` INT, IN `flag` INT)
BEGIN
    DECLARE s VARCHAR(512);
    DECLARE s2 VARCHAR(512);
    DECLARE t VARCHAR(128);
    
    DECLARE selImgMode INT DEFAULT 0;
    DECLARE selCountMode INT DEFAULT 0;
    
    IF flag = -1 THEN
     SET selCountMode = 1;
    END IF;
    
    IF flag = -2 THEN
     SET selCountMode = 1;
     SET selImgMode = 1;
 END IF;
    IF flag = 2 THEN
     SET selImgMode = 1;
 END IF;
 
 SET s = '';
        
    IF selCountMode = 1 THEN
     SET s = CONCAT(s,'SELECT COUNT(*) FROM ');
     
     SET s = CONCAT(s,'pkrss_rssitem_l', lid, ' AS a WHERE 1=1');
     
     IF tid != 0 THEN
         SET s = CONCAT(s,' AND a.tid=', tid);
     END IF;
 
     IF cid != 0 THEN
         SET s = CONCAT(s,' AND a.cid=', cid);
     END IF;
     
     IF selImgMode = 1 THEN
         SET s = CONCAT(s,' AND a.item_imgs is not null');
     END IF;
     
     SET @t2 = s;
     PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
     
 ELSE
    
  SET s = CONCAT(s,'SELECT a.*');
  
  IF tid = 0 THEN
         SET s = CONCAT(s,',t.title AS table_name');
     END IF;
 
     IF cid = 0 THEN
         SET s = CONCAT(s,',c.text AS catalog_name,c.`cls` AS catalog_cls');
     END IF;
 
  SET s = CONCAT(s,' FROM pkrss_rssitem_l', lid, ' AS a');
  
     IF tid = 0 THEN
         SET s = CONCAT(s,' LEFT JOIN pkrss_rsstable AS t ON t.id = a.tid');
     END IF;
 
     IF cid = 0 THEN
         SET s = CONCAT(s,' LEFT JOIN pkrss_rsscatalog AS c ON c.id = a.cid');
     END IF;
 
     SET s = CONCAT(s,' WHERE 1=1');
     
     IF selImgMode = 1 THEN
      SET s = CONCAT(s,' AND a.item_imgs is not null');
     END IF;
 
     IF tid != 0 THEN
         SET s = CONCAT(s,' AND a.tid=', tid);
     END IF;
 
     IF cid != 0 THEN
         SET s = CONCAT(s,' AND a.cid=', cid);
     END IF;
     
     IF flag = 3 THEN
      # get top 1 item with each table
      SET s = CONCAT(s,' AND a.id IN (SELECT MAX(id) FROM pkrss_rssitem_l', lid, ' GROUP BY tid)');
      # select * from pkrss_rssitem_l2 where id in (select max(id) from pkrss_rssitem_l2 group by tid) order by tid,id desc limit 20;
     ELSEIF flag = 4 THEN
   # get top 3 records with each table   
   SET s = CONCAT('SET @num := 0, @tid := 0;', s);
   SET s = CONCAT(s,' AND a.id IN (SELECT id FROM (SELECT id,@num := if(@tid=tid, @num + 1, 1) as row_number,@tid := tid as other_tid');
   SET s = CONCAT(s,' FROM pkrss_rssitem_l', lid, ' ORDER BY tid,id DESC) WHERE row_number<=3)');
   # set @num := 0, @tid := 0;
   # select b.* from (
   #  select a.*, 
   #  @num := if(@tid=tid, @num + 1, 1) as row_number, 
   #  @tid := a.tid as other_tid 
   #  from pkrss_rssitem_l2 as a 
   #  order by a.tid,a.id desc
   # ) as b 
   # where b.row_number <= 3 order by b.tid,b.id desc limit 20;
     END IF;
 
     SET s = CONCAT(s,' ORDER BY');
 
     IF idOrderBy != 0 THEN
         IF idOrderBy > 0 THEN
             SET s = CONCAT(s,' a.id ASC');
         ELSE
             SET s = CONCAT(s,' a.id DESC');
         END IF;
     ELSE
      IF timeOrderBy > 0 THEN
           SET s = CONCAT(s,' a.item_pubdate ASC');
         ELSE
           SET s = CONCAT(s,' a.item_pubdate DESC');
         END IF;
     END IF;
 
     SET s = CONCAT(s,' LIMIT ', offset, ',', `limit`);
          
     SET t = CONCAT('_tmp_',UUID());
     SET @t2 = CONCAT('CREATE TEMPORARY TABLE IF NOT EXISTS `', t,'` (`id` int(11),
    `tid` int(11),
    `cid` int(11),
    `item_pubdate` datetime,
    `item_title` varchar(127) COLLATE utf8_bin,
    `item_desc` varchar(246) COLLATE utf8_bin,
    `item_link` varchar(246) COLLATE ascii_bin,
    `item_authors` varchar(64) COLLATE utf8_bin,
    `item_imgs` text COLLATE utf8_bin,
    `table_name` varchar(127) COLLATE utf8_bin,
    `catalog_name` varchar(64) COLLATE utf8_bin,
    `catalog_cls` varchar(32) COLLATE utf8_bin
    );');
    
     PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
     
     SET s2 = CONCAT('INSERT INTO `', t, '` (`id`,`tid`,`cid`,`item_pubdate`,`item_title`,`item_desc`, `item_link`,`item_authors`,`item_imgs`');
     IF tid = 0 THEN
         SET s2 = CONCAT(s2,',`table_name`');
     END IF;
 
     IF cid = 0 THEN
         SET s2 = CONCAT(s2,',catalog_name,catalog_cls');
     END IF;
     
     SET @t2 = CONCAT(s2,') ', s, ';');
     
  PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
     
     set @t2 = CONCAT('SELECT * FROM `',t,'`');
     PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
    END IF;
   
END;;
DELIMITER ;

And mysql return below error message

CREATE PROCEDURE `pkrss_get_rssitem_vo`(IN `lid` INT, IN `cid` INT, IN `tid` INT, IN `offset` INT, IN `limit` INT, IN `idOrderBy` INT, IN `timeOrderBy` INT, IN `flag` INT)
BEGIN
    DECLARE s VARCHAR(512)
MySQL 返回: 文档

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

How to fixed

add "DELIMITER ;;" to front and end rows:

DELIMITER ;;
CREATE PROCEDURE `pkrss_get_rssitem_vo`(IN `lid` INT, IN `cid` INT, IN `tid` INT, IN `offset` INT, IN `limit` INT, IN `idOrderBy` INT, IN `timeOrderBy` INT, IN `flag` INT)
BEGIN
    DECLARE s VARCHAR(512);
    DECLARE s2 VARCHAR(512);
    DECLARE t VARCHAR(128);
    
    DECLARE selImgMode INT DEFAULT 0;
    DECLARE selCountMode INT DEFAULT 0;
    
    IF flag = -1 THEN
     SET selCountMode = 1;
    END IF;
    
    IF flag = -2 THEN
     SET selCountMode = 1;
     SET selImgMode = 1;
 END IF;
    IF flag = 2 THEN
     SET selImgMode = 1;
 END IF;
 
 SET s = '';
        
    IF selCountMode = 1 THEN
     SET s = CONCAT(s,'SELECT COUNT(*) FROM ');
     
     SET s = CONCAT(s,'pkrss_rssitem_l', lid, ' AS a WHERE 1=1');
     
     IF tid != 0 THEN
         SET s = CONCAT(s,' AND a.tid=', tid);
     END IF;
 
     IF cid != 0 THEN
         SET s = CONCAT(s,' AND a.cid=', cid);
     END IF;
     
     IF selImgMode = 1 THEN
         SET s = CONCAT(s,' AND a.item_imgs is not null');
     END IF;
     
     SET @t2 = s;
     PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
     
 ELSE
    
  SET s = CONCAT(s,'SELECT a.*');
  
  IF tid = 0 THEN
         SET s = CONCAT(s,',t.title AS table_name');
     END IF;
 
     IF cid = 0 THEN
         SET s = CONCAT(s,',c.text AS catalog_name,c.`cls` AS catalog_cls');
     END IF;
 
  SET s = CONCAT(s,' FROM pkrss_rssitem_l', lid, ' AS a');
  
     IF tid = 0 THEN
         SET s = CONCAT(s,' LEFT JOIN pkrss_rsstable AS t ON t.id = a.tid');
     END IF;
 
     IF cid = 0 THEN
         SET s = CONCAT(s,' LEFT JOIN pkrss_rsscatalog AS c ON c.id = a.cid');
     END IF;
 
     SET s = CONCAT(s,' WHERE 1=1');
     
     IF selImgMode = 1 THEN
      SET s = CONCAT(s,' AND a.item_imgs is not null');
     END IF;
 
     IF tid != 0 THEN
         SET s = CONCAT(s,' AND a.tid=', tid);
     END IF;
 
     IF cid != 0 THEN
         SET s = CONCAT(s,' AND a.cid=', cid);
     END IF;
     
     IF flag = 3 THEN
      # get top 1 item with each table
      SET s = CONCAT(s,' AND a.id IN (SELECT MAX(id) FROM pkrss_rssitem_l', lid, ' GROUP BY tid)');
      # select * from pkrss_rssitem_l2 where id in (select max(id) from pkrss_rssitem_l2 group by tid) order by tid,id desc limit 20;
     ELSEIF flag = 4 THEN
   # get top 3 records with each table   
   SET s = CONCAT('SET @num := 0, @tid := 0;', s);
   SET s = CONCAT(s,' AND a.id IN (SELECT id FROM (SELECT id,@num := if(@tid=tid, @num + 1, 1) as row_number,@tid := tid as other_tid');
   SET s = CONCAT(s,' FROM pkrss_rssitem_l', lid, ' ORDER BY tid,id DESC) WHERE row_number<=3)');
   # set @num := 0, @tid := 0;
   # select b.* from (
   #  select a.*, 
   #  @num := if(@tid=tid, @num + 1, 1) as row_number, 
   #  @tid := a.tid as other_tid 
   #  from pkrss_rssitem_l2 as a 
   #  order by a.tid,a.id desc
   # ) as b 
   # where b.row_number <= 3 order by b.tid,b.id desc limit 20;
     END IF;
 
     SET s = CONCAT(s,' ORDER BY');
 
     IF idOrderBy != 0 THEN
         IF idOrderBy > 0 THEN
             SET s = CONCAT(s,' a.id ASC');
         ELSE
             SET s = CONCAT(s,' a.id DESC');
         END IF;
     ELSE
      IF timeOrderBy > 0 THEN
           SET s = CONCAT(s,' a.item_pubdate ASC');
         ELSE
           SET s = CONCAT(s,' a.item_pubdate DESC');
         END IF;
     END IF;
 
     SET s = CONCAT(s,' LIMIT ', offset, ',', `limit`);
          
     SET t = CONCAT('_tmp_',UUID());
     SET @t2 = CONCAT('CREATE TEMPORARY TABLE IF NOT EXISTS `', t,'` (`id` int(11),
    `tid` int(11),
    `cid` int(11),
    `item_pubdate` datetime,
    `item_title` varchar(127) COLLATE utf8_bin,
    `item_desc` varchar(246) COLLATE utf8_bin,
    `item_link` varchar(246) COLLATE ascii_bin,
    `item_authors` varchar(64) COLLATE utf8_bin,
    `item_imgs` text COLLATE utf8_bin,
    `table_name` varchar(127) COLLATE utf8_bin,
    `catalog_name` varchar(64) COLLATE utf8_bin,
    `catalog_cls` varchar(32) COLLATE utf8_bin
    );');
    
     PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
     
     SET s2 = CONCAT('INSERT INTO `', t, '` (`id`,`tid`,`cid`,`item_pubdate`,`item_title`,`item_desc`, `item_link`,`item_authors`,`item_imgs`');
     IF tid = 0 THEN
         SET s2 = CONCAT(s2,',`table_name`');
     END IF;
 
     IF cid = 0 THEN
         SET s2 = CONCAT(s2,',catalog_name,catalog_cls');
     END IF;
     
     SET @t2 = CONCAT(s2,') ', s, ';');
     
  PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
     
     set @t2 = CONCAT('SELECT * FROM `',t,'`');
     PREPARE stmt FROM @t2;
     EXECUTE stmt;
     DEALLOCATE PREPARE stmt;
    END IF;
   
END;;
DELIMITER ;






Friday, June 2, 2017

中国大陆交易所2017年最新行情数据Level1费用与证券财经数据服务咨询汇总

背景

现在我在福建海峡互联网金融信息服务有限公司,老板考虑企业转型,才被逼着考虑买上深行情,但是因为钱的问题,不知道会不会买。他最近一直让我问上、深所的数据报价。以前像我们公司这种做现货的小金融公司太多,国家查得严,最近倒了很多,我们老板不想倒,才考虑做合规产品。 这样没有后顾之忧,以后要上市要融资了,这些都会查的。

下面是个人最近2017年上半年咨询行情报价的情况汇总,仅供参考,不做为确切真实依据,如果有侵权,请告知,第一时间删除。

汇总情况

于上深交所Level1服务费用包括:数据提示牌照费用+数据传输费用。
      如我们现在急着只需要微信和移动的Level1单平台无线增值平台证券行情费用,预计需要上交所牌照费用30/+上交所Internet数据传输免费+深交所牌照费用30/+深圳通云数据传输费用(8000/+8/年)=68.8/年(预计)。其中正式购买后才可以申请最长不超过2个月的测试期。
      另外关于目前炒股软件里的财经F10新闻资讯巨潮资讯由深交所信息公司提供,价格见附件《巨潮数据库服务报价单2016.pdf》,因为隐私问题,如需商务使用,可私人联系我索要
    

Level1数据提示牌照授权费

深交所牌照费用: PC电脑终端30/年,无线终端(微信+APP30/年,或者同时采购两款平台价格打8=30+30*0.8=48/年。
上交所牌照费用: 单平台终端报价与深交所类似,但两款平台同时采购价约45/年。
注意:深交所有要求,一次性申请两个应用可以打八折,如果你们 分开申请,比如先申请无线, 过半年后再申请软件,是不能打折的。以后年度就是续约了。。。按照合同来续约的。
        上交所暂未确认此打折疑问。

Level1数据汇总费用 

采购一款深Level1平台价格=1平台数据提示牌照授权费+数据传输费=30/+15/=45/
采购两款深Level1平台价格=2平台数据提示牌照授权费+数据传输费=48/+15/=63/
数据传输方面单独申请接入,也需要先采购申请提示牌照授权。
Level1据传输费多选1a.因系统升级要求,现有旧协议暂弃(费用好像也是免费),新协议预计2017年第4季度预计推出(可能免费); b.基于api接口供客户端直接调用形式预计2018年初上线,可以先填申请表;c.与深圳通合作,提供专线与云行情两种形式预计省外均为15/年(未确认);d.与第三方公司合作,可能像我们之前联系的汇通网,汇通网之前报过行情数据10/;
深圳通在公司取得行情授权后提供上证与深证行情数据有偿数据传输服务,报价分两种:a.云行情,提供低档云服务器租售5000/年,高档云服务器租售8000/年,提供互联网数据传输带宽租售25M带宽8/年;b.提供专线6M带宽10几万/条,深Level1行情数据预计需拉2条;

采购一款上Level1平台价格=1平台数据提示牌照授权费+数据传输费=30/+数据传输费
采购两款上Level1平台价格=2平台数据提示牌照授权费+数据传输费=45/+数据传输费
Level1数据传输费31a.卫星5; b.专线免费; c.Internet传输免费。

深平台界限范围

网页浏览、查询: PC电脑网页
软件应用揭示: 传统WindowsLinuxMac桌面终端软件应用
无线增值类:IOSAndroidWindows Mobile手机app软件应用及微信H5网页
3款平台一起订深交所牌照费用也是打8

汇总回答2

== 上证所L1行情 申请要求 ==
我们公司应该可以申请,无特殊要求(但是上一次说需要上一年收入材料,如年检)。

== 上证所L2行情 费用 ==
35万许可费+按每终端授权使用费用*终端用户数+3条专线费用。
按每终端授权使用费用计算方法:PC电脑30元/月/台,月保底7.2万,超出另计;手机15元/月/终端,月保底5万,超出另计。
3条专线费用:以深交所为例20万/年*3条,上交所费用稍低。

== 上证所L2行情 申请要求 ==
需要至少签过2、3年上证所L1行情数据后,且需要获取证监会牌照后方可申请。

== 上证所L1、L2行情 区别 ==
L2数据的主要特点是能看到资金流向和十档买卖盘,比L1数据更加清晰和全面。具体可以在上交所网站上下载对应文档进行查看。

== 数据销售与使用 ==
不允许以原始数据进行销售与使用,需要对数据进行有所加工方可销售与使用。

== 之前的几千万费用是什么服务 ==
07年左右有上过通赢数据,后来就中止该服务。

 相关联系人

深交所Level1联系电话:因为隐私问题,如需商务使用,可私人联系我索要
深圳通联系信息: http://www.sscc.com/main/index.shtml
深圳通接入联系人:
        卫星、专线接入联系:因为隐私问题,如需商务使用,可私人联系我索要
        云行情接入联系:深证通,因为隐私问题,如需商务使用,可私人联系我索要 
上交所Level2联系电话:因为隐私问题,如需商务使用,可私人联系我索要

上交所Level1联系电话:因为隐私问题,如需商务使用,可私人联系我索要

Sunday, May 28, 2017

apache shindig java maven compile success log



2015/10/23 - Apache Shindig has been retired. For more information please explore the Attic.

apache shindig java maven compile success log

1. get apache shindig 2.5.2 latest
http://archive.apache.org/dist/shindig/2.5.2/shindig-2.5.2-source.zip

2. how to compiler shindig-2.5.2-source

unzip this source.

edit shindig-2.5.2-source\pom.xml, comment below code:
<!--
    <repository>
      <id>diff_match_patch</id>
      <url>http://google-diff-match-patch.googlecode.com/svn/trunk/maven</url>
    </repository>
    <repository>
      <id>caja</id>
      <url>http://google-caja.googlecode.com/svn/maven</url>
    </repository>
    <repository>
      <id>oauth</id>
      <url>http://oauth.googlecode.com/svn/code/maven</url>
    </repository>
    -->

and change:
<groupId>diff_match_patch</groupId>
<artifactId>diff_match_patch</artifactId>
to:
<groupId>org.webjars</groupId>
<artifactId>google-diff-match-patch</artifactId>

edit shindig-2.5.2-source\features\pom.xml, comment below code:
<!--
  <pluginRepositories>
    <pluginRepository>
      <id>jsdoctk2</id>
      <url>http://jsdoctk-plugin.googlecode.com/svn/repo</url>
    </pluginRepository>
  </pluginRepositories>
-->

edit shindig-2.5.2-source\java\gadgets\pom.xml,change:
<groupId>diff_match_patch</groupId>
<artifactId>diff_match_patch</artifactId>
to:
<groupId>org.webjars</groupId>
<artifactId>google-diff-match-patch</artifactId>

3. compile
> mvn package -Dmaven.test.skip=true

4. Last result
[INFO] --- maven-site-plugin:3.2:attach-descriptor (attach-descriptor) @ shindig-server ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Apache Shindig Project ............................. SUCCESS [  2.125 s]
[INFO] Apache Shindig Features ............................ SUCCESS [  5.049 s]
[INFO] Apache Shindig Common Code ......................... SUCCESS [  7.014 s]
[INFO] Apache Shindig Gadget Renderer ..................... SUCCESS [ 12.246 s]
[INFO] Apache Shindig Social API .......................... SUCCESS [  4.275 s]
[INFO] Apache Shindig Sample Container .................... SUCCESS [  1.981 s]
[INFO] Apache Shindig Sample Web App Maven Archetype ...... SUCCESS [ 11.330 s]
[INFO] Apache Shindig Web App Resources ................... SUCCESS [  3.129 s]
[INFO] Apache Shindig Extra Modules ....................... SUCCESS [  3.474 s]
[INFO] Apache Shindig Web App Dependencies ................ SUCCESS [  0.690 s]
[INFO] Apache Shindig Web App ............................. SUCCESS [  4.492 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.284 s
[INFO] Finished at: 2017-05-29T10:33:37+08:00
[INFO] Final Memory: 56M/817M

[INFO] ------------------------------------------------------------------------

5. Edit in eclipse(or Sts)

5.1 shindig-gadgets properties > Java Build Path: Delete src/test/java and src/test/resource

5.2 edit shindig-server/pom.xml:
<build>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
           <!-- add below one row -->
          <failOnMissingWebXml>false</failOnMissingWebXml>
          ...

Sunday, May 21, 2017

com.netflix.client.ClientException: Load balancer does not have available server for client:

What:
Spring boot feignclient call other instance show below error:
com.netflix.client.ClientException: Load balancer does not have available server for client:

Why:
if eureka.client.fetchRegistry is false, the various shuffle methods in com.netflix.discovery.shared.Applications are not called and hence Applications.shuffleVirtualHostNameMap is never populated. This map is used later for look up in the method Applications.getInstancesByVirtualHostName that then fails.
How:
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true # change to true, is ok

Last:
Thanks

Friday, May 5, 2017

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: myzc_string_record is not mapped

What

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: myzc_string_record is not mapped
 at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:171) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:76) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:321) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3687) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3576) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:716) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:572) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:309) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:257) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
 ... 58 common frames omitted


Why

Below is my old query sql. and i used it in spring boot jpa environment:
@Query(value = "select key_type,max(key_id) from myzc_string_record group by key_type")
 Map selectMaxKeyTypeAndId();

How
Below is my new query sql,add nativeQuery = true:
@Query(value = "select key_type,max(key_id) from myzc_string_record group by key_type", nativeQuery = true)
 Map selectMaxKeyTypeAndId();

Last
Thanks!

Caused by: java.lang.IllegalArgumentException: This class [class com.myzc98.server.domain.JsonRecordDomain] does not define an IdClass

Below is my error message:

Caused by: java.lang.IllegalArgumentException: This class [class com.myzc98.server.domain.JsonRecordDomain] does not define an IdClass
 at org.hibernate.jpa.internal.metamodel.AbstractIdentifiableType.getIdClassAttributes(AbstractIdentifiableType.java:183) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
 at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$IdMetadata.(JpaMetamodelEntityInformation.java:253) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.(JpaMetamodelEntityInformation.java:84) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:68) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.SimpleJpaRepository.(SimpleJpaRepository.java:110) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at com.myzc98.server.mapper.MyMapperImpl.(MyMapperImpl.java:15) ~[classes/:na]
 at com.myzc98.server.mapper.MyMapperFactoryBean$CustomRepositoryFactory.getTargetRepository(MyMapperFactoryBean.java:38) ~[classes/:na]
 at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:199) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
 at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101) ~[spring-data-jpa-1.11.1.RELEASE.jar:na]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
 ... 30 common frames omitted

Why:
Because i used Composite Primary Key in JsonRecordDomain.

How to fixed it, add @IdClass composite annotation:

@Entity
@Table(name = "myzc_json_record")
@IdClass(String2LongId.class)
public class JsonRecordDomain implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 主键类型
     */
    @Id
    @Column(name = "key_type")
    private String keyType;

    /**
     * 主键类型 ID
     */
    @Id
    @Column(name = "key_id")
    private Long keyId;

    // ...
}

public class String2LongId implements Serializable {
 /**
  * 
  */
 private static final long serialVersionUID = 1L;
 
 @Column(nullable = false)
 private String keyType;

 @Column(nullable = true)
 private Long keyId;

 public String2LongId() {
 }

 public String2LongId(String keyType, Long keyId) {
  this.keyType = keyType;
  this.keyId = keyId;
 }

 public String getKeyType() {
  return keyType;
 }

 public void setKeyType(String keyType) {
  this.keyType = keyType;
 }

 public Long getKeyId() {
  return keyId;
 }

 public void setKeyId(Long keyId) {
  this.keyId = keyId;
 }

 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((keyType == null) ? 0 : keyType.hashCode());
  result = prime * result + ((keyId == null) ? 0 : keyId.hashCode());
  return result;
 }

 @Override
 public boolean equals(Object obj) {
  do{
   if (this == obj)
    return true;
   
   if (obj == null)
    break;
   
   if (!String2LongId.class.equals(obj.getClass()))
    break;
   
   String2LongId other = (String2LongId) obj;
   if (this.keyType == null) {
    if (other.keyType != null)
     break;
   }else if(!this.keyType.equals(other.keyType)){
    break;
   }
   
   if (this.keyId == null) {
    if (other.keyId != null)
     break;
   }else if(!this.keyId.equals(other.keyId)){
    break;
   }
   
   return true;
  }while(false);
  
  return false;
 }

 @Override
 public String toString() {
  return "String2LongId [keyType=" + keyType + ", keyId=" + keyId + "]";
 }
}

Thursday, April 27, 2017

spring boot some error log draft


1.What
> java.lang.NoClassDefFoundError jackson.databind.exc.InvalidDefinitionException

Why
because i used spring boot 2.0.0.BUILD-SNAPSHOT, it reference jackson-databind 2.9.0.pr3, but i manual code reference  jackson-databind with old version 2.5.1 in my pom.xml.

How
delete my old 2.5.1 reference, it is ok!

2. What
> Caused by: java.lang.IllegalStateException: You need to configure a uri for the git repository

Why
because i used spring config with native not git mode,and spring.cloud.config.server.native need match with spring.profiles.active=native

How
define below row in application profile:
spring.profiles.active=native

3.What
> Binding to target org.springframework.cloud.config.server.environment.NativeEnvironmentRepository@1584c019 failed:

    Property: spring.cloud.config.server.native.searchLocations
    Value: null
    Reason: Property 'searchLocations' threw exception; nested exception is java.lang.NullPointerException

    Property: spring.cloud.config.server.native.searchLocations
    Value: null,null
    Reason: Property 'searchLocations' threw exception; nested exception is java.lang.NullPointerException

Why
my code is like below, i do not known which is yaml right grammar:
spring:
  cloud:
    config:
      server:
        native:
          search-locations:
          - classpath:/config/
          - classpath:/config/${spring.profiles.active}

How
change to below ,it can run no error:
spring:
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config/, classpath:/config/${spring.profiles.active}

4. What
> Caused by: java.lang.NoSuchMethodError: com.netflix.servo.monitor.Monitors.isObjectRegistered(Ljava/lang/String;Ljava/lang/Object;)Z

Why
 may be is maven spring boot reference jar version confit, see Wrong dependencies on spring cloud #3316.

How
reference servo-core with new version 0.10+, for example:

<dependency>
    <groupId>com.netflix.servo</groupId>
    <artifactId>servo-core</artifactId>
    <version>0.12.16</version>
</dependency>

5.What
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;

Why
Because Spring-Cloud-Config-Server reference spring-aop (1.3.0.RELEASE) with 4.3.7, but spring-boot-startor (1.3.0.RELEASE)  reference spring-aop with 4.3.8, and org.springframework.aop.framework.AopProxyUtils.getSingletonTarget sina 4.3.8,see here

How
reference spring-aop with new version 4.3.8, for example:

<dependency>
    <groupId>com.netflix.servo</groupId>
    <artifactId>servo-core</artifactId>
    <version>0.12.16</version>
</dependency>

6. What
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.filter.TokenFilter

Why
Because Spring-Cloud-Startor-Eureka(1.3.0.RELEASE) reference jackson-core(2.4.3), but spring-cloud-config-server(1.3.0.RELEASE) reference jackson-databind(2.8.7)

How
reference jackson-core with new version 2.8.8, for example:

<dependency>
    <groupId>com.netflix.archaius</groupId>
    <artifactId>archaius-core</artifactId>
    <version>0.7.5</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.8</version>
</dependency>

7. What
Caused by: java.lang.ClassNotFoundException: com.ecwid.consul.v1.ConsulClient

Why

How
<dependency>
    <groupId>com.ecwid.consul</groupId>
    <artifactId>consul-api</artifactId>
    <version>1.2.2</version>
</dependency>

8. What
Description Resource Path Location Type
Class dependency error 'org/springframework/integration/dsl/IntegrationFlow' occurred on aspect definition 'Aspect definition [\myzc_microsrv_consul\src\main\java\consul\Application.java:-1] advise type [after] advise [com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(org.aspectj.lang.ProceedingJoinPoint)]' while processing bean 'org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration (53) [org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration]'. Check if builder classpath is complete Application.java /myzc_microsrv_consul/src/main/java/consul line 53 Spring AOP Problem

How
<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-java-dsl</artifactId>
    <version>1.2.1.RELEASE</version>
</dependency>

9. What
Class dependency error 'org/joda/time/Period'

How
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
   <version>2.9.9</version>
</dependency>

10. What
Class dependency error 'org/springframework/cloud/bus/event/RemoteApplicationEvent' occurred on aspect definition 'Aspect definition [\myzc_microsrv_consul\src\main\java\consul\Application.java:-1] advise type [after] advise [org.springframework.cloud.netflix.metrics.RestTemplateUrlTemplateCapturingAspect.captureUrlTemplate(org.aspectj.lang.ProceedingJoinPoint)]' while processing bean 'application (53) [consul.Application]'. Check if builder classpath is complete Application.java /myzc_microsrv_consul/src/main/java/consul line 53 Spring AOP Problem

How
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-bus</artifactId>
    <version>1.3.0.RELEASE</version>
</dependency>

11. What
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server ...
or
com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: Host name may not be null ...

Why
I used eureka hostname has only word,not split with '.'
eureka:
  instance:
    hostname: myzc_microsrv_config
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://myzc_microsrv_discovery:8761/eureka/

How change host name with '.' not '_'
defaultZone: http://myzc.microsrv.discovery:8761/eureka/

12. What
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.WebApplicationType


Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.bind.PlaceholdersResolver

 
Caused by: java.lang.ClassNotFoundException: class org.springframework.cloud.client.HostInfoEnvironmentPostProcessor

How
in parent's project, edit pom.xml:
    <parent>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>Camden.SR6</version>
        <relativePath/>
    </parent>

13.
What
spring boot jpa Not a managed type:

How:
In application main class,add annotation:
@EntityScan("your domain package name")

14.
What Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Map, at table: myzc_json_record, for columns: [org.hibernate.mapping.Column(ext)]

How:
see How to use Postgres JSONB datatype with JPA?.