In this paper we assume the insurance wealth process is driven by the compound Poisson process. The discounting factor is modelled as a geometric Brownian motion at first and then as an exponential function of an integrated Ornstein-Uhlenbeck process. The objective is to maximize the cumulated value of expected discounted dividends up to the time of ruin. We give an explicit expression of the value function and the optimal strategy in the case of interest rate following a geometric Brownian motion. For the case of the Vasicek model, we explore some properties of the value function. Since we can not find an explicit expression for the value function in the second case, we prove that the value function is the viscosity solution of the corresponding HJB equation.